Java Code Examples for org.junit.Assert.assertTrue()

The following are Jave code examples for showing how to use assertTrue() of the org.junit.Assert class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: PEF   File: LiveCaptureTest.java   View Source Code Vote up 6 votes
@Ignore("This interface does not exist anymore")
@Test
public void compareOutputJNetPcapMetal() throws IOException{
    // Create a dumper using both the libraries. Wrapper around the others.
    final String[] cmd = String.format("-4 30313233343536373839414243444546 /16 test -c all %s",
        Paths.get(".").toAbsolutePath().normalize().toString()).split(" ");
    LiveCapture.main(cmd);
    final File metalFile = new File("metal-test.pcap");
    final File jnetpcapFile = new File("jnetpcap-test.pcap");
    //There is not test for comparing with the reference file because if no DNS was found
    // no packets have been modified.
    final File referenceFile = new File("reference");

    Assert.assertTrue("The files should be identical!", FileUtils.contentEquals(metalFile, jnetpcapFile));

    // Temporary cleanup.
    if (metalFile.exists()) {
        metalFile.delete();
    }
    if (jnetpcapFile.exists()) {
        jnetpcapFile.delete();
    }
    if (referenceFile.exists()) {
        referenceFile.delete();
    }
}
 
Example 2
Project: haystack-client-java   File: SpanBuilderTest.java   View Source Code Vote up 6 votes
@Test
public void testWithTags() {
    Span child = tracer.buildSpan("child")
        .withTag("string-key", "string-value")
        .withTag("boolean-key", false)
        .withTag("number-key", 1l)
        .startManual();

    Map<String, ?> tags = child.getTags();

    Assert.assertEquals(3, tags.size());
    Assert.assertTrue(tags.containsKey("string-key"));
    Assert.assertEquals("string-value", tags.get("string-key"));
    Assert.assertTrue(tags.containsKey("boolean-key"));
    Assert.assertEquals(false, tags.get("boolean-key"));
    Assert.assertTrue(tags.containsKey("number-key"));
    Assert.assertEquals(1l, tags.get("number-key"));
}
 
Example 3
Project: aliyun-maxcompute-data-collectors   File: TestMainframeFTPClientUtils.java   View Source Code Vote up 6 votes
@Test
public void testAnonymous_VERBOSE_IllegelPort() {
  try {
    when(mockFTPClient.login("anonymous", "")).thenReturn(true);
    when(mockFTPClient.logout()).thenReturn(true);
    when(mockFTPClient.isConnected()).thenReturn(false);
    when(mockFTPClient.getReplyCode()).thenReturn(200);
  } catch (IOException e) {
    fail("No IOException should be thrown!");
  }

  conf.set(DBConfiguration.URL_PROPERTY, "localhost:testPort");
  conf.setBoolean(JobBase.PROPERTY_VERBOSE, true);

  FTPClient ftp = null;
  boolean success = false;
  try {
    ftp = MainframeFTPClientUtils.getFTPConnection(conf);
  } catch (IOException ioe) {
    fail("No IOException should be thrown!");
  } finally {
    success = MainframeFTPClientUtils.closeFTPConnection(ftp);
  }
  Assert.assertTrue(success);
}
 
Example 4
Project: java-threading   File: JoinableFutureContextTest.java   View Source Code Vote up 6 votes
@Test
public void testHangReportNotSuppressedOnLongRunningFutureCompleted() {
	getFactory().setHangDetectionTimeout(Duration.ofMillis(10));
	AtomicBoolean hangReported = new AtomicBoolean(false);
	getContext().onReportHang = (hangDuration, iterations, id) -> hangReported.set(true);

	JoinableFuture<Void> task = getFactory().runAsync(
		() -> Async.awaitAsync(Async.delayAsync(Duration.ofMillis(30))),
		EnumSet.of(JoinableFutureCreationOption.LONG_RUNNING));

	task.join();
	Assert.assertFalse(hangReported.get());

	JoinableFutureCollection taskCollection = new JoinableFutureCollection(getFactory().getContext());
	taskCollection.add(task);

	getFactory().run(() -> Async.usingAsync(
		taskCollection.join(),
		tempJoin -> Async.awaitAsync(Async.delayAsync(Duration.ofMillis(30)))));

	Assert.assertTrue(hangReported.get());
}
 
Example 5
Project: libris   File: OpticalCharacterRecognitionSearchTest.java   View Source Code Vote up 6 votes
public void testAzureOcrSearchReturnNotNull() {
    try {
        URL url = new URL("https://i.ytimg.com/vi/0E4PWHTS4BA/hqdefault.jpg");
        String key = System.getenv("AZURE_KEY");
        IAzureOcrResult res = OpticalCharacterRecognitionSearch
                .getAzureServices(key)
                .imageSearchBuildQuery()
                .setImage(url)
                .build()
                .search();
        org.junit.Assert.assertNotNull(res);
    } catch (Exception e) {
        e.printStackTrace();
        Assert.assertTrue(false);
    }
}
 
Example 6
Project: SkipList   File: SkipListMapTest.java   View Source Code Vote up 6 votes
@Test
public void testHeadMap() throws Exception {
    for (int i = 0; i < 100; i++) {
        map.put(i, String.valueOf(i));
    }
    SortedMap<Integer, String> headMap = map.headMap(74);
    Assert.assertEquals(74, headMap.size());
    for (int i = 0; i < 74; i++) {
        Assert.assertTrue(headMap.containsKey(i));
    }
    Assert.assertFalse(headMap.containsKey(74));

    SortedMap<Integer, String> headHeadMap = headMap.headMap(53);
    Assert.assertEquals(53, headHeadMap.size());
    for (int i = 0; i < 53; i++) {
        Assert.assertTrue(headHeadMap.containsKey(i));
    }
    Assert.assertFalse(headHeadMap.containsKey(53));

}
 
Example 7
Project: hadoop   File: ViewFsBaseTest.java   View Source Code Vote up 6 votes
@Test(expected=AccessControlException.class) 
public void testInternalRename2() throws IOException {
  Assert.assertTrue("linkTODir2 should be a dir", 
      fcView.getFileStatus(new Path("/internalDir/linkToDir2")).isDirectory());
  fcView.rename(new Path("/internalDir/linkToDir2"),
      new Path("/internalDir/dir1"));
}
 
Example 8
Project: EasyPackage   File: PathUtilTest.java   View Source Code Vote up 5 votes
@Test
public void testGetPath1() {
    Config.setContextPath4Test("/appName");

    System.out.println(PathUtil.getPath(""));

    Assert.assertTrue(PathUtil.getPath("").equals(
            Config.getContextPath() + "/"));
    Assert.assertTrue(PathUtil.getPath("/").equals(
            Config.getContextPath() + "/"));
    Assert.assertTrue(PathUtil.getPath("index").equals(
            Config.getContextPath() + "/index"));
    Assert.assertTrue(PathUtil.getPath("/index").equals(
            Config.getContextPath() + "/index"));
}
 
Example 9
Project: apache-tomcat-7.0.73-with-comment   File: TestListELResolver.java   View Source Code Vote up 5 votes
/**
 * Tests that a valid property is resolved.
 */
@Test
public void testGetValue03() {
    ListELResolver resolver = new ListELResolver();
    ELContext context = new ELContextImpl();

    List<String> list = new ArrayList<String>();
    list.add("key");
    Object result = resolver.getValue(context, list, new Integer(0));

    Assert.assertEquals("key", result);
    Assert.assertTrue(context.isPropertyResolved());
}
 
Example 10
Project: devops-cstack   File: ContainerCommandTests.java   View Source Code Vote up 5 votes
@Test
public void test40_startContainerWithPorts() throws DockerJSONException {
    container = ContainerUtils.newStartInstance(container.getName(), null, null, false);
    dockerCloudUnitClient.startContainer(container);
    Assert.assertTrue((dockerCloudUnitClient.findContainer(container).getNetworkSettings().getPorts().toString()
            .contains("22")));

}
 
Example 11
Project: incubator-servicecomb-java-chassis   File: TestHighwayCodec.java   View Source Code Vote up 5 votes
@Test
public void testEncodeRequest() {
  boolean status = true;
  try {
    commonMock();
    TcpOutputStream os = HighwayCodec.encodeRequest(0, invocation, operationProtobuf, null);
    Assert.assertNotNull(os);
    Assert.assertArrayEquals(TcpParser.TCP_MAGIC, os.getBuffer().getBytes(0, 7));
  } catch (Exception e) {
    status = false;
  }
  Assert.assertTrue(status);
}
 
Example 12
Project: datax   File: ConfigurationTest.java   View Source Code Vote up 5 votes
@Test
public void test_getKeys() {
	Set<String> sets = new HashSet<String>();

	sets.clear();
	Configuration configuration = Configuration.from("{}");
	System.out.println(JSON.toJSONString(configuration.getKeys()));
	Assert.assertTrue(configuration.getKeys().isEmpty());

	sets.clear();
	configuration = Configuration.from("[]");
	System.out.println(JSON.toJSONString(configuration.getKeys()));
	Assert.assertTrue(configuration.getKeys().isEmpty());

	sets.clear();
	configuration = Configuration.from("[0]");
	System.out.println(JSON.toJSONString(configuration.getKeys()));
	Assert.assertTrue(configuration.getKeys().contains("[0]"));

	sets.clear();
	configuration = Configuration.from("[1,2]");
	System.out.println(JSON.toJSONString(configuration.getKeys()));
	Assert.assertTrue(configuration.getKeys().contains("[0]"));
	Assert.assertTrue(configuration.getKeys().contains("[1]"));

	sets.clear();
	configuration = Configuration.from("[[[0]]]");
	System.out.println(JSON.toJSONString(configuration.getKeys()));
	Assert.assertTrue(configuration.getKeys().contains("[0][0][0]"));

	sets.clear();
	configuration = Configuration
			.from("{\"a\":{\"b\":{\"c\":[0],\"B\": \"B\"},\"A\": \"A\"}}");
	System.out.println(JSON.toJSONString(configuration.getKeys()));
	Assert.assertTrue(JSON.toJSONString(configuration.getKeys()).equals(
			"[\"a.b.B\",\"a.b.c[0]\",\"a.A\"]"));
}
 
Example 13
Project: linkifier   File: RegressionTest.java   View Source Code Vote up 5 votes
@Test
public void test327() throws Throwable {
    if (debug)
        System.out.format("%n%s%n", "RegressionTest0.test327");
    Column column2 = new Column(",", "");
    column2.setEstimatedRowCount((int) (byte) 0);
    column2.setPrimaryKey(true);
    column2.setKeywordSingleton();
    String str8 = column2.getDataTypeName();
    String str9 = column2.getLongName();
    Assert.assertNull(str8);
    Assert.assertTrue("'" + str9 + "' != '" + ",." + "'", str9.equals(",."));
}
 
Example 14
Project: Cypher   File: ClientTest.java   View Source Code Vote up 5 votes
@Test
public void getPublicRooms() throws IOException {

	// Collect rooms
	Map rooms = client.getPublicRooms("test");

	// Make sure they were collected properly
	Assert.assertTrue(rooms.size() == 2);
	Assert.assertNotNull(rooms.get("ID1"));
	Assert.assertNotNull(rooms.get("ID2"));
}
 
Example 15
Project: teemo   File: WebviewIndexSwitcherTest.java   View Source Code Vote up 5 votes
@Test
public void testGetPattern() {
	WebviewIndexSwitcher<?> s = new WebviewIndexSwitcher<>(getBasicContextSwitcher(0));
	Pattern p = s.getPattern();
	Assert.assertNotNull(p);
	Assert.assertTrue(p.matcher("WEBVIEW[1]").matches());
	Assert.assertTrue(p.matcher("WEBVIEW[-1]").matches());
	Assert.assertFalse(p.matcher("WEBVIEW[]").matches());
}
 
Example 16
Project: dubbocloud   File: JavaBeanSerializeUtilTest.java   View Source Code Vote up 4 votes
@Test
public void testBeanSerialize() throws Exception {
    Bean bean = new Bean();
    bean.setDate(new Date());
    bean.setStatus(PersonStatus.ENABLED);
    bean.setType(Bean.class);
    bean.setArray(new Phone[]{});

    Collection<Phone> collection = new ArrayList<Phone>();
    bean.setCollection(collection);
    Phone phone = new Phone();
    collection.add(phone);

    Map<String, FullAddress> map = new HashMap<String, FullAddress>();
    FullAddress address = new FullAddress();
    map.put("first", address);
    bean.setAddresses(map);

    JavaBeanDescriptor descriptor = JavaBeanSerializeUtil.serialize(bean, JavaBeanAccessor.METHOD);
    Assert.assertTrue(descriptor.isBeanType());
    assertEqualsPrimitive(bean.getDate(), descriptor.getProperty("date"));
    assertEqualsEnum(bean.getStatus(), descriptor.getProperty("status"));
    Assert.assertTrue(((JavaBeanDescriptor)descriptor.getProperty("type")).isClassType());
    Assert.assertEquals(Bean.class.getName(), ((JavaBeanDescriptor)descriptor.getProperty("type")).getClassNameProperty());
    Assert.assertTrue(((JavaBeanDescriptor)descriptor.getProperty("array")).isArrayType());
    Assert.assertEquals(0, ((JavaBeanDescriptor)descriptor.getProperty("array")).propertySize());

    JavaBeanDescriptor property = (JavaBeanDescriptor)descriptor.getProperty("collection");
    Assert.assertTrue(property.isCollectionType());
    Assert.assertEquals(1, property.propertySize());
    property = (JavaBeanDescriptor)property.getProperty(0);
    Assert.assertTrue(property.isBeanType());
    Assert.assertEquals(Phone.class.getName(), property.getClassName());
    Assert.assertEquals(0, property.propertySize());

    property = (JavaBeanDescriptor)descriptor.getProperty("addresses");
    Assert.assertTrue(property.isMapType());
    Assert.assertEquals(bean.getAddresses().getClass().getName(), property.getClassName());
    Assert.assertEquals(1, property.propertySize());


    Map.Entry<Object, Object> entry = property.iterator().next();
    Assert.assertTrue(((JavaBeanDescriptor)entry.getKey()).isPrimitiveType());
    Assert.assertEquals("first", ((JavaBeanDescriptor)entry.getKey()).getPrimitiveProperty());

    Assert.assertTrue(((JavaBeanDescriptor)entry.getValue()).isBeanType());
    Assert.assertEquals(FullAddress.class.getName(), ((JavaBeanDescriptor)entry.getValue()).getClassName());
    Assert.assertEquals(0, ((JavaBeanDescriptor)entry.getValue()).propertySize());
}
 
Example 17
Project: hadoop   File: TestFairScheduler.java   View Source Code Vote up 4 votes
@Test
public void testSchedulingOnRemovedNode() throws Exception {
  // Disable continuous scheduling, will invoke continuous scheduling manually
  scheduler.init(conf);
  scheduler.start();
  Assert.assertTrue("Continuous scheduling should be disabled.",
      !scheduler.isContinuousSchedulingEnabled());

  ApplicationAttemptId id11 = createAppAttemptId(1, 1);
  createMockRMApp(id11);

  scheduler.addApplication(id11.getApplicationId(), "root.queue1", "user1",
      false);
  scheduler.addApplicationAttempt(id11, false, false);

  List<ResourceRequest> ask1 = new ArrayList<>();
  ResourceRequest request1 =
      createResourceRequest(1024, 8, 8, ResourceRequest.ANY, 1, 1, true);

  ask1.add(request1);
  scheduler.allocate(id11, ask1, new ArrayList<ContainerId>(), null,
      null);

  String hostName = "127.0.0.1";
  RMNode node1 = MockNodes.newNodeInfo(1,
    Resources.createResource(8 * 1024, 8, 8), 1, hostName);
  NodeAddedSchedulerEvent nodeEvent1 = new NodeAddedSchedulerEvent(node1);
  scheduler.handle(nodeEvent1);

  FSSchedulerNode node = (FSSchedulerNode)scheduler.getSchedulerNode(
    node1.getNodeID());

  NodeRemovedSchedulerEvent removeNode1 =
      new NodeRemovedSchedulerEvent(node1);
  scheduler.handle(removeNode1);

  scheduler.attemptScheduling(node);

  AppAttemptRemovedSchedulerEvent appRemovedEvent1 =
      new AppAttemptRemovedSchedulerEvent(id11,
          RMAppAttemptState.FINISHED, false);
  scheduler.handle(appRemovedEvent1);
}
 
Example 18
Project: liferay-service-builder-dsl   File: EntityTest.java   View Source Code Vote up 4 votes
@Test
public void testBuildWithJsonSerializationFromRemoteService() {
	Entity entity = builder.withRemoteServices().build();

	Assert.assertTrue(entity.hasJsonSerialization());
}
 
Example 19
Project: plugin-prov   File: ImportCatalogResourceTest.java   View Source Code Vote up 4 votes
@Test
public void findAll() {
	final ImportCatalogResource resource = newResource();

	// Add importable provider
	resource.locator = Mockito.mock(ServicePluginLocator.class);
	final ImportCatalogService service = Mockito.mock(ImportCatalogService.class);
	Mockito.when(resource.locator.getResource("service:prov:test", ImportCatalogService.class)).thenReturn(service);

	// Add not updatable provider node
	final Node notImportNode = new Node();
	notImportNode.setId("service:prov:any");
	notImportNode.setName("Cannot import");
	notImportNode.setRefined(nodeRepository.findOneExpected("service:prov"));
	nodeRepository.saveAndFlush(notImportNode);

	final List<CatalogVo> catalogs = resource.findAll();
	Assert.assertEquals(3, catalogs.size());

	// This provider does not support catalog update
	Assert.assertEquals(0, catalogs.get(0).getStatus().getNbInstancePrices().intValue());
	Assert.assertNull(catalogs.get(0).getStatus().getEnd());
	Assert.assertNull(catalogs.get(0).getStatus().getStart());
	Assert.assertEquals("service:prov:any", catalogs.get(0).getNode().getId());
	Assert.assertFalse(catalogs.get(0).isCanImport());
	Assert.assertEquals(0, catalogs.get(0).getNbQuotes());

	// This provider supports catalog update
	Assert.assertNotNull(catalogs.get(1).getStatus());
	Assert.assertEquals("service:prov:test", catalogs.get(1).getNode().getId());
	Assert.assertTrue(catalogs.get(1).isCanImport());
	Assert.assertEquals(2, catalogs.get(1).getNbQuotes());

	// This provider does not support catalog update
	Assert.assertEquals("service:prov:x", catalogs.get(2).getNode().getId());
	Assert.assertFalse(catalogs.get(2).isCanImport());
	Assert.assertNull(catalogs.get(2).getStatus().getEnd());
	Assert.assertNull(catalogs.get(2).getStatus().getStart());
	Assert.assertEquals(1, catalogs.get(2).getNbQuotes());

	final ImportCatalogStatus status = catalogs.get(1).getStatus();
	Assert.assertEquals(DEFAULT_USER, status.getAuthor());
	Assert.assertNull(status.getEnd());
	Assert.assertNull(status.getLocation());
	Assert.assertEquals("service:prov:test", status.getLocked().getId());
	Assert.assertNotNull(status.getStart());
	Assert.assertEquals(0, status.getDone());
	Assert.assertEquals(0, status.getWorkload());
}
 
Example 20
Project: https-github.com-apache-zookeeper   File: QuorumUtilTest.java   View Source Code Vote up 4 votes
/**
 * <p>
 * This test ensures that all JXM beans associated to a {@link QuorumPeer}
 * are unregistered when shuted down ({@link QuorumUtil#shutdown(int)}). It
 * allows a successfull restarting of several zookeeper servers (
 * {@link QuorumPeer}) running on the same JVM.
 * <p>
 * See ZOOKEEPER-1214 for details.
 */
@Test
public void validateAllMXBeanAreUnregistered() throws IOException {
    QuorumUtil qU = new QuorumUtil(1);
    LOG.info(">-->> Starting up all servers...");
    qU.startAll();
    LOG.info(">-->> Servers up and running...");

    int leaderIndex = qU.getLeaderServer();
    int firstFollowerIndex = 0;
    int secondFollowerIndex = 0;

    switch (leaderIndex) {
    case 1:
        firstFollowerIndex = 2;
        secondFollowerIndex = 3;
        break;
    case 2:
        firstFollowerIndex = 1;
        secondFollowerIndex = 3;
        break;
    case 3:
        firstFollowerIndex = 1;
        secondFollowerIndex = 2;
        break;

    default:
        Assert.fail("Unexpected leaderIndex value: " + leaderIndex);
        break;
    }

    LOG.info(">-->> Shuting down server [{}]", firstFollowerIndex);
    qU.shutdown(firstFollowerIndex);
    LOG.info(">-->> Shuting down server [{}]", secondFollowerIndex);
    qU.shutdown(secondFollowerIndex);
    LOG.info(">-->> Restarting server [{}]", firstFollowerIndex);
    qU.restart(firstFollowerIndex);
    LOG.info(">-->> Restarting server [{}]", secondFollowerIndex);
    qU.restart(secondFollowerIndex);

    qU.shutdownAll();
    Set<ZKMBeanInfo> pending = MBeanRegistry.getInstance()
            .getRegisteredBeans();
    Assert.assertTrue("The following beans should have been unregistered: "
            + pending, pending.isEmpty());
}