Java Code Examples for org.testng.Assert#assertNull()

The following examples show how to use org.testng.Assert#assertNull() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestTreeCache.java    From xian with Apache License 2.0 6 votes vote down vote up
@Test
public void testStartup() throws Exception
{
    client.create().forPath("/test");
    client.create().forPath("/test/1", "one".getBytes());
    client.create().forPath("/test/2", "two".getBytes());
    client.create().forPath("/test/3", "three".getBytes());
    client.create().forPath("/test/2/sub", "two-sub".getBytes());

    cache = newTreeCacheWithListeners(client, "/test");
    cache.start();
    assertEvent(TreeCacheEvent.Type.NODE_ADDED, "/test");
    assertEvent(TreeCacheEvent.Type.NODE_ADDED, "/test/1", "one".getBytes());
    assertEvent(TreeCacheEvent.Type.NODE_ADDED, "/test/2", "two".getBytes());
    assertEvent(TreeCacheEvent.Type.NODE_ADDED, "/test/3", "three".getBytes());
    assertEvent(TreeCacheEvent.Type.NODE_ADDED, "/test/2/sub", "two-sub".getBytes());
    assertEvent(TreeCacheEvent.Type.INITIALIZED);
    assertNoMoreEvents();

    Assert.assertEquals(cache.getCurrentChildren("/test").keySet(), ImmutableSet.of("1", "2", "3"));
    Assert.assertEquals(cache.getCurrentChildren("/test/1").keySet(), ImmutableSet.of());
    Assert.assertEquals(cache.getCurrentChildren("/test/2").keySet(), ImmutableSet.of("sub"));
    Assert.assertNull(cache.getCurrentChildren("/test/non_exist"));
}
 
Example 2
Source File: MultiLimiterTest.java    From incubator-gobblin with Apache License 2.0 6 votes vote down vote up
@Test
public void test() throws Exception {

  CountBasedLimiter countLimiter1 = new CountBasedLimiter(3);
  CountBasedLimiter countLimiter2 = new CountBasedLimiter(1);

  MultiLimiter multiLimiter = new MultiLimiter(countLimiter1, countLimiter2);

  // Can only take 1 permit (limiter2 has only 1 permit available)
  Assert.assertNotNull(multiLimiter.acquirePermits(1));
  Assert.assertNull(multiLimiter.acquirePermits(1));

  // limiter1 has 1 leftover permit (one consumed in the failed second permit above)
  Assert.assertNotNull(countLimiter1.acquirePermits(1));
  Assert.assertNull(countLimiter1.acquirePermits(1));

  // limiter2 has not leftover permits
  Assert.assertNull(countLimiter2.acquirePermits(1));
}
 
Example 3
Source File: CGatherTest.java    From scheduler with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * We try to relocate co-located VMs in continuous mode. Not allowed
 *
 * @throws org.btrplace.scheduler.SchedulerException
 */
@Test
public void testContinuousWithRelocationOfVMs() throws SchedulerException {
    Model mo = new DefaultModel();
    VM vm1 = mo.newVM();
    VM vm2 = mo.newVM();
    Node n1 = mo.newNode();
    Node n2 = mo.newNode();
    Mapping map = mo.getMapping().on(n1, n2).run(n2, vm1, vm2);
    Gather g = new Gather(map.getAllVMs());
    g.setContinuous(true);
    List<SatConstraint> cstrs = new ArrayList<>();
    cstrs.addAll(Running.newRunning(map.getAllVMs()));
    cstrs.add(g);
    cstrs.add(new Fence(vm1, Collections.singleton(n1)));
    cstrs.add(new Fence(vm2, Collections.singleton(n1)));
    ChocoScheduler cra = new DefaultChocoScheduler();
    ReconfigurationPlan plan = cra.solve(mo, cstrs);
    Assert.assertNull(plan);
}
 
Example 4
Source File: DefaultReconfigurationProblemTest.java    From scheduler with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Exhibit issue #43
 */
@Test
public void testMultipleStates() {
    Model mo = new DefaultModel();
    VM vm0 = mo.newVM();
    Node n0 = mo.newNode();
    mo.getMapping().ready(vm0).on(n0);

    ReconfigurationProblem rp = new DefaultReconfigurationProblemBuilder(mo)
            .setNextVMsStates(new HashSet<>(Arrays.asList(vm0)),
                    new HashSet<>(Arrays.asList(vm0)),
                    new HashSet<>(Arrays.asList(vm0)),
                    new HashSet<>(Arrays.asList(vm0))
            ).build();
    Assert.assertNull(rp.solve(2, false));
}
 
Example 5
Source File: PersistenceStoreObjectAccessorWriterTestFixture.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
@Test
public void testLastModifiedTime() throws Exception {
    accessor.delete();
    Assert.assertNull(accessor.getLastModifiedDate());
    accessor.put("abc");
    accessor.waitForCurrentWrites(TIMEOUT);
    Date write1 = accessor.getLastModifiedDate();
    Assert.assertNotNull(write1);
    
    Time.sleep(getLastModifiedResolution().multiply(2));
    accessor.put("abc");
    accessor.waitForCurrentWrites(TIMEOUT);
    Date write2 = accessor.getLastModifiedDate();
    Assert.assertNotNull(write2);
    Assert.assertTrue(write2.after(write1), "dates are "+write1+" ("+write1.getTime()+") and "+write2+" ("+write2.getTime()+") ");
}
 
Example 6
Source File: DeletesTest.java    From tasmo with Apache License 2.0 5 votes vote down vote up
@Test (dataProvider = "tasmoMaterializer", invocationCount = 1, singleThreaded = true)
public void testBackRefTailOfPathDeleted(TasmoMaterializerHarness t) throws Exception {
    String viewClassName = "Values";
    String viewFieldName = "userInfo";
    String path = viewClassName + "::" + viewFieldName
        + "::Version.backRefs.Content.ref_version|Content.backRefs.User.ref_content|User.userName";
    Views views = TasmoModelFactory.modelToViews(path);
    t.initModel(views);
    ObjectId version1 = t.write(EventBuilder.create(t.idProvider(), "Version", tenantId, actorId).build());
    ObjectId content1 = t.write(EventBuilder.create(t.idProvider(), "Content", tenantId, actorId).set("ref_version", version1).build());
    ObjectId user1 = t.write(EventBuilder
        .create(t.idProvider(), "User", tenantId, actorId).set("userName", "ted").set("ref_content", content1).build());

    t.readView(tenantId, actorId, new ObjectId(viewClassName, version1.getId()), Id.NULL);
    t.addExpectation(version1, viewClassName, viewFieldName, new ObjectId[]{ version1, content1, user1 }, "userName", "ted");
    t.assertExpectation(tenantIdAndCentricId);
    t.clearExpectations();

    ObjectNode view = t.readView(tenantId, actorId, new ObjectId(viewClassName, version1.getId()), Id.NULL);
    Assert.assertNotNull(view);

    t.write(EventBuilder.update(user1, tenantId, actorId).set(ReservedFields.DELETED, true).build());

    view = t.readView(tenantId, actorId, new ObjectId(viewClassName, version1.getId()), Id.NULL);
    Assert.assertNull(view, " view = " + view);

    t.write(EventBuilder.update(content1, tenantId, actorId).set("ref_version", version1).build());
    view = t.readView(tenantId, actorId, new ObjectId(viewClassName, content1.getId()), Id.NULL);
    Assert.assertNull(view);
}
 
Example 7
Source File: XmlElementTest.java    From butterfly with MIT License 5 votes vote down vote up
@Test
public void noXmlTest() {
    XmlElement xmlElement = new XmlElement().setXmlElement("project").relative("src/main/resources/dogs.yaml");
    TUExecutionResult executionResult = xmlElement.execution(transformedAppFolder, transformationContext);
    Assert.assertEquals(executionResult.getType(), TUExecutionResult.Type.ERROR);
    Assert.assertNull(executionResult.getValue());
    Assert.assertEquals(xmlElement.getDescription(), "Retrieve the value of element project in XML file src/main/resources/dogs.yaml");
    Assert.assertNotNull(executionResult.getException());
    Assert.assertEquals(executionResult.getException().getClass(), TransformationUtilityException.class);
    Assert.assertEquals(executionResult.getException().getMessage(), "File content could not be parsed properly in XML format");
}
 
Example 8
Source File: TestDistributedDelayQueue.java    From curator with Apache License 2.0 5 votes vote down vote up
@Test
public void     testLateAddition() throws Exception
{
    Timing                          timing = new Timing();
    DistributedDelayQueue<Long>     queue = null;
    CuratorFramework                client = CuratorFrameworkFactory.newClient(server.getConnectString(), timing.session(), timing.connection(), new RetryOneTime(1));
    client.start();
    try
    {
        BlockingQueueConsumer<Long> consumer = new BlockingQueueConsumer<Long>(Mockito.mock(ConnectionStateListener.class));
        queue = QueueBuilder.builder(client, consumer, new LongSerializer(), "/test").buildDelayQueue();
        queue.start();

        queue.put(1L, System.currentTimeMillis() + Integer.MAX_VALUE);  // never come out
        Long        value = consumer.take(1, TimeUnit.SECONDS);
        Assert.assertNull(value);

        queue.put(2L, System.currentTimeMillis());
        value = consumer.take(timing.seconds(), TimeUnit.SECONDS);
        Assert.assertEquals(value, Long.valueOf(2));

        value = consumer.take(1, TimeUnit.SECONDS);
        Assert.assertNull(value);
    }
    finally
    {
        CloseableUtils.closeQuietly(queue);
        CloseableUtils.closeQuietly(client);
    }
}
 
Example 9
Source File: LRUCacheTest.java    From aws-secretsmanager-caching-java with Apache License 2.0 5 votes vote down vote up
@Test
public void removeWithValueTest() {
    LRUCache<Integer, Integer> cache = new LRUCache<Integer, Integer>();
    cache.put(1, 1);
    Assert.assertNotNull(cache.get(1));
    Assert.assertFalse(cache.remove(1, 2));
    Assert.assertNotNull(cache.get(1));
    Assert.assertTrue(cache.remove(1, 1));
    Assert.assertNull(cache.get(1));
}
 
Example 10
Source File: ActionTestControllerTest.java    From dolphin-platform with Apache License 2.0 5 votes vote down vote up
/** Start BigDecimal Type Related Action Test */
@Test
public void callPublicMethodWithBigDecimalParam() {
    Assert.assertNull(controller.getModel().getBigDecimalValue());
    final BigDecimal value = new BigDecimal(10);
    controller.invoke(PUBLIC_WITH_BIGDECIMAL_PARAM_ACTION, new Param(PARAM_NAME, value));
    Assert.assertEquals(controller.getModel().getBigDecimalValue(), value);
}
 
Example 11
Source File: CollectOxoGMetricsTest.java    From picard with MIT License 5 votes vote down vote up
@Test(dataProvider = "RightOptions")
public void testPositiveCustomCommandLineValidation(final int minimumInsertSize,
                                                    final int maximumInsertSize,
                                                    final int contextSize,
                                                    final HashSet<String> context) throws Exception {
    final CollectOxoGMetrics collectOxoGMetrics = getCollectOxoGMetrics(minimumInsertSize, maximumInsertSize, contextSize, context);
    Assert.assertNull(collectOxoGMetrics.customCommandLineValidation());
    Assert.assertEquals(collectOxoGMetrics.MINIMUM_INSERT_SIZE, minimumInsertSize);
    Assert.assertEquals(collectOxoGMetrics.MAXIMUM_INSERT_SIZE, maximumInsertSize);
    Assert.assertEquals(collectOxoGMetrics.CONTEXT_SIZE, contextSize);
    Assert.assertEquals(collectOxoGMetrics.CONTEXTS, context);
}
 
Example 12
Source File: TestRecordStream.java    From incubator-gobblin with Apache License 2.0 5 votes vote down vote up
@Test
public void testFlushFailure() throws Exception {
  FlushAckable flushAckable1 = new FlushAckable();
  FlushAckable flushAckable2 = new FlushAckable();

  MyExtractor extractor = new MyExtractor(new StreamEntity[]{new RecordEnvelope<>("a"),
      FlushControlMessage.builder().flushReason("flush1").build().addCallBack(flushAckable1), new RecordEnvelope<>("b"),
      FlushControlMessage.builder().flushReason("flushFail1").build().addCallBack(flushAckable2)});
  MyConverter converter = new MyConverter();
  MyFlushDataWriter writer = new MyFlushDataWriter();

  Task task = setupTask(extractor, writer, converter);

  task.run();

  // first flush should succeed, but second one should fail
  Throwable error = flushAckable1.waitForAck();
  Assert.assertNull(error);

  error = flushAckable2.waitForAck();
  Assert.assertNotNull(error);

  task.commit();
  Assert.assertEquals(task.getTaskState().getWorkingState(), WorkUnitState.WorkingState.FAILED);

  Assert.assertEquals(converter.records, Lists.newArrayList("a", "b"));
  Assert.assertEquals(converter.messages, Lists.newArrayList(
      FlushControlMessage.builder().flushReason("flush1").build(),
      FlushControlMessage.builder().flushReason("flushFail1").build()));

  Assert.assertEquals(writer.records, Lists.newArrayList("a", "b"));
  Assert.assertEquals(writer.flush_messages, Lists.newArrayList("flush called"));
}
 
Example 13
Source File: SaajEmptyNamespaceTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testAddElementToNullNsNoDeclarations() throws Exception {
    // Create empty SOAP message
    SOAPMessage msg = createSoapMessage();
    SOAPBody body = msg.getSOAPPart().getEnvelope().getBody();

    // Add elements
    SOAPElement parentExplicitNS = body.addChildElement("content", "", TEST_NS);
    SOAPElement childGlobalNS = parentExplicitNS.addChildElement("global-child", "", null);
    SOAPElement childDefaultNS = parentExplicitNS.addChildElement("default-child");

    // Check namespace URIs
    Assert.assertNull(childGlobalNS.getNamespaceURI());
    Assert.assertEquals(childDefaultNS.getNamespaceURI(), TEST_NS);
}
 
Example 14
Source File: HopscotchMultiMapTest.java    From gatk with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
void findTest() {
    final HopscotchMultiMap<Integer, Integer, IntPair> hopscotchMultiMap = new HopscotchMultiMap<>(testVals);
    for ( final IntPair entry : testVals ) {
        Assert.assertEquals(hopscotchMultiMap.find(entry.getKey()).getKey(), entry.getKey());
    }
    Assert.assertNull(hopscotchMultiMap.find(notInTestVals));
}
 
Example 15
Source File: JUnit4TestReportLoaderTest.java    From citrus-admin with Apache License 2.0 5 votes vote down vote up
@Test
public void testResult() throws Exception {
    Assert.assertTrue(service.hasTestResults(project));

    TestReport report = service.getLatest(project, test1);
    Assert.assertEquals(report.getResults().size(), 1L);
    Assert.assertEquals(report.getTotal(), 1L);
    Assert.assertEquals(report.getPassed(), 1L);
    Assert.assertEquals(report.getFailed(), 0L);
    Assert.assertEquals(report.getResults().get(0).getTest().getClassName(), "Test_1_IT");
    Assert.assertEquals(report.getResults().get(0).getTest().getName(), "Test_1_IT.test_1");
    Assert.assertEquals(report.getResults().get(0).getTest().getMethodName(), "test_1");
    Assert.assertEquals(report.getResults().get(0).getTest().getPackageName(), "com.consol.citrus.samples");
    Assert.assertTrue(report.getResults().get(0).getStatus().equals(TestStatus.PASS));
    Assert.assertNull(report.getResults().get(0).getErrorCause());

    report = service.getLatest(project, test3);
    Assert.assertEquals(report.getResults().size(), 1L);
    Assert.assertEquals(report.getTotal(), 1L);
    Assert.assertEquals(report.getPassed(), 0L);
    Assert.assertEquals(report.getFailed(), 1L);
    Assert.assertEquals(report.getResults().get(0).getTest().getClassName(), "Test_3_IT");
    Assert.assertEquals(report.getResults().get(0).getTest().getName(), "Test_3_IT.test_3");
    Assert.assertEquals(report.getResults().get(0).getTest().getMethodName(), "test_3");
    Assert.assertEquals(report.getResults().get(0).getTest().getPackageName(), "com.consol.citrus.samples");
    Assert.assertTrue(report.getResults().get(0).getStatus().equals(TestStatus.FAIL));
    Assert.assertEquals(report.getResults().get(0).getErrorCause(), "com.consol.citrus.exceptions.TestCaseFailedException");
    Assert.assertEquals(report.getResults().get(0).getErrorMessage(), "Test case failed");
    Assert.assertNotNull(report.getResults().get(0).getStackTrace());
}
 
Example 16
Source File: TestFramework.java    From curator with Apache License 2.0 5 votes vote down vote up
@Test
public void testBackgroundDeleteWithChildren() throws Exception
{
    CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), new RetryOneTime(1));
    client.start();
    try
    {
        client.getCuratorListenable().addListener
            ((client1, event) ->
            {
                if ( event.getType() == CuratorEventType.DELETE )
                {
                    Assert.assertEquals(event.getPath(), "/one/two");
                    ((CountDownLatch)event.getContext()).countDown();
                }
            });

        CountDownLatch latch = new CountDownLatch(1);
        AsyncCuratorFramework async = AsyncCuratorFramework.wrap(client);
        async.create().withOptions(EnumSet.of(CreateOption.createParentsIfNeeded)).forPath("/one/two/three/four").thenRun(() ->
            async.delete().withOptions(EnumSet.of(DeleteOption.deletingChildrenIfNeeded)).forPath("/one/two").handle((v, e) -> {
                Assert.assertNull(v);
                Assert.assertNull(e);
                latch.countDown();
                return null;
            })
        );
        Assert.assertTrue(latch.await(10, TimeUnit.SECONDS));
        Assert.assertNull(client.checkExists().forPath("/one/two"));
    }
    finally
    {
        CloseableUtils.closeQuietly(client);
    }
}
 
Example 17
Source File: ReportEntityObserverTest.java    From extentreports-java with Apache License 2.0 5 votes vote down vote up
@Test
public void disposableNonNull() {
    ExtentReports extent = new ExtentReports();
    Assert.assertNull(disp);
    Assert.assertNull(entity);
    extent.attachReporter(new TestReporter());
    Assert.assertNotNull(disp);
    Assert.assertNull(entity);
    extent.flush();
    Assert.assertNotNull(disp);
    Assert.assertNotNull(entity);
}
 
Example 18
Source File: SynchronizedElementBuilderTest.java    From scheduler with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Test
public void testVMRegistration() {
    DefaultElementBuilder de = new DefaultElementBuilder();
    ElementBuilder eb = new SynchronizedElementBuilder(de);
    VM v = eb.newVM();
    VM vX = eb.newVM();
    Assert.assertNotEquals(v, vX);
    Assert.assertTrue(eb.contains(v));
    Assert.assertNull(eb.newVM(v.id()));

    int nextId = v.id() + 1000;
    VM v2 = eb.newVM(nextId);
    Assert.assertTrue(eb.contains(v2));
}
 
Example 19
Source File: SeqTest.java    From jenetics with Apache License 2.0 5 votes vote down vote up
@Test
public void toArray3() {
	final Seq<String> mseq = MSeq.of("1", "2");
	final Object[] array = mseq.toArray(new Object[]{"a", "b", "c", "d"});

	Assert.assertEquals(array.length, 4);
	Assert.assertEquals(array[0], mseq.get(0));
	Assert.assertEquals(array[1], mseq.get(1));
	Assert.assertNull(array[2]);
	Assert.assertEquals(array[3], "d");
}
 
Example 20
Source File: DefaultMetadataServiceTest.java    From incubator-atlas with Apache License 2.0 4 votes vote down vote up
@Test
public void testArrayOfStructs() throws Exception {
    //Add array of structs
    TestUtils.dumpGraph(TestUtils.getGraph());

    final Struct partition1 = new Struct(TestUtils.PARTITION_STRUCT_TYPE);
    partition1.set(NAME, "part1");

    final Struct partition2 = new Struct(TestUtils.PARTITION_STRUCT_TYPE);
    partition2.set(NAME, "part2");

    List<Struct> partitions = new ArrayList<Struct>(){{ add(partition1); add(partition2); }};
    table.set("partitions", partitions);

    String newtableId = updateInstance(table).getUpdateEntities().get(0);
    assertEquals(newtableId, tableId._getId());

    String tableDefinitionJson =
        metadataService.getEntityDefinition(TestUtils.TABLE_TYPE, NAME, (String) table.get(NAME));
    Referenceable tableDefinition = InstanceSerialization.fromJsonReferenceable(tableDefinitionJson, true);

    Assert.assertNotNull(tableDefinition.get("partitions"));
    List<Struct> partitionsActual = (List<Struct>) tableDefinition.get("partitions");
    assertPartitions(partitionsActual, partitions);

    //add a new element to array of struct
    final Struct partition3 = new Struct(TestUtils.PARTITION_STRUCT_TYPE);
    partition3.set(NAME, "part3");
    partitions.add(partition3);
    table.set("partitions", partitions);
    newtableId = updateInstance(table).getUpdateEntities().get(0);
    assertEquals(newtableId, tableId._getId());

    tableDefinitionJson =
        metadataService.getEntityDefinition(TestUtils.TABLE_TYPE, NAME, (String) table.get(NAME));
    tableDefinition = InstanceSerialization.fromJsonReferenceable(tableDefinitionJson, true);

    Assert.assertNotNull(tableDefinition.get("partitions"));
    partitionsActual = (List<Struct>) tableDefinition.get("partitions");
    assertPartitions(partitionsActual, partitions);

    //remove one of the struct values
    partitions.remove(1);
    table.set("partitions", partitions);
    newtableId = updateInstance(table).getUpdateEntities().get(0);
    assertEquals(newtableId, tableId._getId());

    tableDefinitionJson =
        metadataService.getEntityDefinition(TestUtils.TABLE_TYPE, NAME, (String) table.get(NAME));
    tableDefinition = InstanceSerialization.fromJsonReferenceable(tableDefinitionJson, true);

    Assert.assertNotNull(tableDefinition.get("partitions"));
    partitionsActual = (List<Struct>) tableDefinition.get("partitions");
    assertPartitions(partitionsActual, partitions);

    //Update struct value within array of struct
    partitions.get(0).set(NAME, "part4");
    newtableId = updateInstance(table).getUpdateEntities().get(0);
    assertEquals(newtableId, tableId._getId());

    tableDefinitionJson =
        metadataService.getEntityDefinition(TestUtils.TABLE_TYPE, NAME, (String) table.get(NAME));
    tableDefinition = InstanceSerialization.fromJsonReferenceable(tableDefinitionJson, true);

    Assert.assertNotNull(tableDefinition.get("partitions"));
    partitionsActual = (List<Struct>) tableDefinition.get("partitions");
    assertPartitions(partitionsActual, partitions);

    //add a repeated element to array of struct
    final Struct partition4 = new Struct(TestUtils.PARTITION_STRUCT_TYPE);
    partition4.set(NAME, "part4");
    partitions.add(partition4);
    table.set("partitions", partitions);
    newtableId = updateInstance(table).getUpdateEntities().get(0);
    assertEquals(newtableId, tableId._getId());

    tableDefinitionJson =
        metadataService.getEntityDefinition(TestUtils.TABLE_TYPE, NAME, (String) table.get(NAME));
    tableDefinition = InstanceSerialization.fromJsonReferenceable(tableDefinitionJson, true);

    Assert.assertNotNull(tableDefinition.get("partitions"));
    partitionsActual = (List<Struct>) tableDefinition.get("partitions");
    assertPartitions(partitionsActual, partitions);


    // Remove all elements. Should set array attribute to null
    partitions.clear();
    newtableId = updateInstance(table).getUpdateEntities().get(0);
    assertEquals(newtableId, tableId._getId());

    tableDefinitionJson =
        metadataService.getEntityDefinition(TestUtils.TABLE_TYPE, NAME, (String) table.get(NAME));
    tableDefinition = InstanceSerialization.fromJsonReferenceable(tableDefinitionJson, true);

    Assert.assertNull(tableDefinition.get("partitions"));
}