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

The following examples show how to use org.testng.Assert#assertNotNull() . 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: DefaultRequestContentTypeTestCase.java    From product-ei with Apache License 2.0 6 votes vote down vote up
@SetEnvironment(executionEnvironments = {ExecutionEnvironment.STANDALONE})
@Test(groups = {"wso2.esb"}, description = "Test for DEFAULT_REQUEST_TYPE for nhttp transport")
public void testReturnContentType() throws Exception {
    try {
        String url = getApiInvocationURL("defaultRequestContentTypeApi").concat("?symbol=wso2");
        HttpUriRequest request = new HttpPut(url);
        DefaultHttpClient client = new DefaultHttpClient();

        ((HttpPut)request).setEntity(new StringEntity("<request/>"));

        HttpResponse response = client.execute(request);
        Assert.assertNotNull(response);
        Assert.assertTrue(getResponse(response).toString().contains("WSO2"));
    } catch (IOException e) {
        log.error("Error while sending the request to the endpoint. ", e);
    }

}
 
Example 2
Source File: AssertNotesESTestCase.java    From product-es with Apache License 2.0 6 votes vote down vote up
@Test(groups = {"wso2.greg", "wso2.greg.es"}, alwaysRun = true,description = "Add note to asset test")
public void addNoteToAsset() throws JSONException, IOException {
    queryParamMap.put("type", "note");
    //  https://localhost:9443/publisher/apis/assets?type=note
    String dataBody = String.format(readFile(resourcePath + "publisherAddNoteRestResource.json")
            , assetType, "testservice1234", noteName);
    ClientResponse response =
            genericRestClient.geneticRestRequestPost(publisherUrl + "/assets",
                                                     MediaType.APPLICATION_JSON,
                                                     MediaType.APPLICATION_JSON, dataBody
                    , queryParamMap, headerMap, cookieHeaderPublisher);
    Assert.assertTrue((response.getStatusCode() == 201),
                      "Wrong status code ,Expected 201 OK ,Received " +
                      response.getStatusCode());
    JSONObject responseObj = new JSONObject(response.getEntity(String.class));
    Assert.assertTrue(responseObj.getJSONObject("attributes").get("overview_note").toString().contains(noteName), "Does not create a note");
    Assert.assertTrue(responseObj.getJSONObject("attributes").get("overview_resourcepath").toString().contains(assetType),"Fault resource path for note");
    noteOverviewHash = responseObj.getJSONObject("attributes").get("overview_hash").toString();
    Assert.assertNotNull(noteOverviewHash);
    noteAssetId =responseObj.get("id").toString();
}
 
Example 3
Source File: DeletesTest.java    From tasmo with Apache License 2.0 6 votes vote down vote up
@Test (dataProvider = "tasmoMaterializer", invocationCount = 1, singleThreaded = true)
public void testDeletes(TasmoMaterializerHarness t) throws Exception {
    String viewClassName = "Values";
    String viewFieldName = "userInfo";
    Views views = TasmoModelFactory.modelToViews(viewClassName + "::" + viewFieldName + "::User.userName,age");
    t.initModel(views);

    ObjectId user1 = t.write(EventBuilder.create(t.idProvider(), "User", tenantId, actorId).set("userName", "ted").build());

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

    Assert.assertNotNull(view);

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

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

}
 
Example 4
Source File: PendingCapabilityDelayedOSGiTest.java    From carbon-kernel with Apache License 2.0 6 votes vote down vote up
/**
 * This test will wait 10 seconds until the TransportManager server is available. Ideally the TransportManager
 * should be available after four seconds.
 */
@Test
public void testDelayedPendingCapabilityRegistration() {
    ServiceReference reference = null;
    for (int i = 0; i < 10; i++) {
        try {
            Thread.sleep(1000);
        } catch (InterruptedException ignore) {

        }
        reference = bundleContext.getServiceReference(TransportManager.class);
        if (reference != null) {
            break;
        }
    }
    Assert.assertNotNull(reference, "Service reference of TransportManager should not be null");
}
 
Example 5
Source File: TsdbResultMergerTests.java    From splicer with Apache License 2.0 6 votes vote down vote up
@Test(expectedExceptions = MergeException.class)
public void tryMergeWithNullTagsInSecond()
{
	TsdbResult obj1 = get("a.b.c");
	TsdbResult obj2 = get("a.b.c");

	HashMap<String, String> t1 = new HashMap<>();
	t1.put("a1", "b1");
	obj1.setTags(new TsdbResult.Tags(t1));

	TsdbResult[] results = merger.merge(new TsdbResult[]{obj1}, new TsdbResult[]{obj2});
	Assert.assertNotNull(results);
	Assert.assertTrue(results.length == 1);
	Assert.assertEquals(results[0].getMetric(), "a.b.c");

	results = merger.merge(new TsdbResult[]{obj2}, new TsdbResult[]{obj1});
	Assert.assertNotNull(results);
	Assert.assertTrue(results.length == 1);
	Assert.assertEquals(results[0].getMetric(), "a.b.c");

	throw new RuntimeException("Should not reach here");
}
 
Example 6
Source File: ETagResponseFilterTest.java    From che with Eclipse Public License 2.0 6 votes vote down vote up
/** Check if ETag is generated for a list of JSON */
@Test
public void filterListEntityTest() throws Exception {

  final ContainerResponse response =
      resourceLauncher.service(
          HttpMethod.GET, SERVICE_PATH + "/list", BASE_URI, null, null, null);
  assertEquals(response.getStatus(), OK.getStatusCode());
  // check entity
  Assert.assertEquals(response.getEntity(), Arrays.asList("a", "b", "c"));
  // Check etag
  List<Object> headerTags = response.getHttpHeaders().get("ETag");
  Assert.assertNotNull(headerTags);
  Assert.assertEquals(headerTags.size(), 1);
  Assert.assertEquals(headerTags.get(0), new EntityTag("900150983cd24fb0d6963f7d28e17f72"));
}
 
Example 7
Source File: SpecifyBothMinMaxByExpressionTestCase.java    From product-ei with Apache License 2.0 6 votes vote down vote up
@Test(groups = {"wso2.esb"}, description = "higher number of messages than minimum count")
public void testMoreNumberThanMinimum() throws IOException, XMLStreamException {
    int responseCount=0;
    no_of_requests=8;
    aggregatedRequestClient.setNoOfIterations(no_of_requests);
    String Response= aggregatedRequestClient.getResponse();
    Assert.assertNotNull(Response);
    OMElement Response2= AXIOMUtil.stringToOM(Response);
    OMElement soapBody = Response2.getFirstElement();
    Iterator iterator =soapBody.getChildrenWithName(new QName("http://services.samples",
            "getQuoteResponse"));

    while (iterator.hasNext()) {
        responseCount++;
        OMElement getQuote = (OMElement) iterator.next();
        Assert.assertTrue(getQuote.toString().contains("IBM"));
    }
    Assert.assertTrue(minMessageCount<=responseCount&&responseCount<=no_of_requests);

}
 
Example 8
Source File: DeviceAgentServiceTest.java    From carbon-device-mgt with Apache License 2.0 5 votes vote down vote up
@Test(description = "Test the get operation method with device management exception.")
public void testGetOperationsWithDeviceManagementException() throws DeviceManagementException {
    PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceManagementService"))
            .toReturn(this.deviceManagementProviderService);
    List<String> deviceTypes = new ArrayList<>();
    deviceTypes.add(TEST_DEVICE_TYPE);
    Mockito.when(this.deviceManagementProviderService.getAvailableDeviceTypes())
            .thenThrow(new DeviceManagementException());
    Response response = this.deviceAgentService.getOperationsByDeviceAndStatus(TEST_DEVICE_TYPE,
            TEST_DEVICE_IDENTIFIER, Operation.Status.COMPLETED);
    Assert.assertNotNull(response, "The response should not be null");
    Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(),
            "The response status should be 500");
    Mockito.reset(this.deviceManagementProviderService);
}
 
Example 9
Source File: YamlRuleConfigParserTest.java    From ratelimiter4j with Apache License 2.0 5 votes vote down vote up
public void testParse() throws IOException {
  YamlRuleConfigParser parser = new YamlRuleConfigParser();
  UniformRuleConfigMapping result = parser.parse(VALID_YAML_1);
  Assert.assertNotNull(result);
  Assert.assertTrue(result.getConfigs().size() == 2);
  print(result);
  System.out.println(System.getProperty("line.separator"));
}
 
Example 10
Source File: RelocatableVMTest.java    From scheduler with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Test
public void testRelocateDueToPreserve() throws SchedulerException {
    Model mo = new DefaultModel();
    Mapping map = mo.getMapping();

    final VM vm1 = mo.newVM();
    final VM vm2 = mo.newVM();
    final VM vm3 = mo.newVM();
    Node n1 = mo.newNode();
    Node n2 = mo.newNode();

    map.addOnlineNode(n1);
    map.addOnlineNode(n2);
    map.addRunningVM(vm1, n1);
    map.addRunningVM(vm2, n1);
    map.addRunningVM(vm3, n2);
    ShareableResource rc = new ShareableResource("cpu", 10, 10);
    rc.setCapacity(n1, 7);
    rc.setConsumption(vm1, 3);
    rc.setConsumption(vm2, 3);
    rc.setConsumption(vm3, 5);

    Preserve pr = new Preserve(vm1, "cpu", 5);
    ChocoScheduler cra = new DefaultChocoScheduler();
    mo.attach(rc);
    List<SatConstraint> cstrs = new ArrayList<>();
    cstrs.addAll(Online.newOnline(map.getAllNodes()));
    cstrs.addAll(Overbook.newOverbooks(map.getAllNodes(), "cpu", 1));
    cstrs.add(pr);
    ReconfigurationPlan p = cra.solve(mo, cstrs);
    Assert.assertNotNull(p);
}
 
Example 11
Source File: BaseSecurityTest.java    From atlas with Apache License 2.0 5 votes vote down vote up
protected File startKDC() throws Exception {
    File target = Files.createTempDirectory("sectest").toFile();
    File kdcWorkDir = new File(target, "kdc");
    Properties kdcConf = MiniKdc.createConf();
    kdcConf.setProperty(MiniKdc.DEBUG, "true");
    kdc = new MiniKdc(kdcConf, kdcWorkDir);
    kdc.start();

    Assert.assertNotNull(kdc.getRealm());
    return kdcWorkDir;
}
 
Example 12
Source File: TestDistributedDelayQueue.java    From curator with Apache License 2.0 5 votes vote down vote up
@Test
public void     testSimple() throws Exception
{
    final int QTY = 10;

    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();

        Random random = new Random();
        for ( int i = 0; i < QTY; ++i )
        {
            long    delay = System.currentTimeMillis() + random.nextInt(100);
            queue.put(delay, delay);
        }

        long            lastValue = -1;
        for ( int i = 0; i < QTY; ++i )
        {
            Long        value = consumer.take(timing.forWaiting().seconds(), TimeUnit.SECONDS);
            Assert.assertNotNull(value);
            Assert.assertTrue(value >= lastValue);
            lastValue = value;
        }
    }
    finally
    {
        CloseableUtils.closeQuietly(queue);
        CloseableUtils.closeQuietly(client);
    }
}
 
Example 13
Source File: GeoLocationProviderServiceTest.java    From carbon-device-mgt with Apache License 2.0 5 votes vote down vote up
@Test(dependsOnMethods = "createGeoStationaryAlert", description = "retrieve saved geo stationary-alert.")
public void getGeoStationaryAlerts() throws GeoLocationBasedServiceException {
    List<GeoFence> geoFences;
    geoFences = geoLocationProviderServiceImpl.getStationaryAlerts(getDeviceIdentifier(), device.getEnrolmentInfo().getOwner());
    Assert.assertNotNull(geoFences);
    GeoFence geoFenceNode = geoFences.get(0);
    Assert.assertEquals(geoFenceNode.getAreaName(), SAMPLE_AREA_NAME);
    Assert.assertEquals(geoFenceNode.getQueryName(), SAMPLE_QUERY_NAME);
    Assert.assertEquals(geoFenceNode.getStationaryTime(), SAMPLE_STATIONARY_TIME);
}
 
Example 14
Source File: SendIntegrationTestCase.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
@SetEnvironment(executionEnvironments = {ExecutionEnvironment.STANDALONE})
@Test(groups = "wso2.esb", description = "Test sending request to Load Balancing Endpoint With the WeightedRoundRobin Algorithm Receiving Sequence in Gov Registry while BuildMessage Enabled")
public void testSendingLoadBalancingEndpoint11() throws IOException {

    String response = lbClient.sendLoadBalanceRequest(getProxyServiceURLHttp("loadBalancingEndPoint11"),
            "http://localhost:9001/services/LBService1");
    Assert.assertNotNull(response);
    Assert.assertTrue(response.toString().contains("Response from server: Server_1"));

    response = lbClient.sendLoadBalanceRequest(getProxyServiceURLHttp("loadBalancingEndPoint11"),
            "http://localhost:9002/services/LBService1");
    Assert.assertNotNull(response);
    Assert.assertTrue(response.toString().contains("Response from server: Server_2"));

    response = lbClient.sendLoadBalanceRequest(getProxyServiceURLHttp("loadBalancingEndPoint11"),
            "http://localhost:9002/services/LBService1");
    Assert.assertNotNull(response);
    Assert.assertTrue(response.toString().contains("Response from server: Server_2"));

    response = lbClient.sendLoadBalanceRequest(getProxyServiceURLHttp("loadBalancingEndPoint11"),
            "http://localhost:9003/services/LBService1");
    Assert.assertNotNull(response);
    Assert.assertTrue(response.toString().contains("Response from server: Server_3"));

    response = lbClient.sendLoadBalanceRequest(getProxyServiceURLHttp("loadBalancingEndPoint11"),
            "http://localhost:9001/services/LBService1");
    Assert.assertNotNull(response);
    Assert.assertTrue(response.toString().contains("Response from server: Server_1"));
}
 
Example 15
Source File: LegacyAvroSchemaTest.java    From avro-util with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Test
public void testMalformedSchemaWorks() throws Exception {
  if (AvroCompatibilityHelper.getRuntimeAvroVersion() != AvroVersion.AVRO_1_4) {
    throw new SkipException("test only valid under avro 1.4");
  }
  String id = "123";
  LegacyAvroSchema legacyAvroSchema = new LegacyAvroSchema(id, badSchemaJson);
  Assert.assertNotNull(legacyAvroSchema);
  Assert.assertEquals(id, legacyAvroSchema.getOriginalSchemaId());
  JSONAssert.assertEquals("minified json should be equal to input", badSchemaJson, legacyAvroSchema.getOriginalSchemaJson(), true);
  Assert.assertEquals(Schema.parse(badSchemaJson), legacyAvroSchema.getFixedSchema());
  Assert.assertNull(legacyAvroSchema.getIssue()); //nothing wrong with it
  Assert.assertTrue(legacyAvroSchema.getTransforms().isEmpty());
}
 
Example 16
Source File: BundleAndTypeResourcesTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Test
public void testListEnrichers() {
    Set<TypeSummary> enrichers = client().path("/catalog/types").query("supertype", "enricher")
            .get(new GenericType<Set<TypeSummary>>() {});

    assertTrue(enrichers.size() > 0);
    TypeSummary asp = null;
    for (TypeSummary p : enrichers) {
        if (Aggregator.class.getName().equals(p.getSymbolicName()))
            asp = p;
    }
    Assert.assertNotNull(asp, "didn't find Aggregator");
}
 
Example 17
Source File: GetEstimateUDFTest.java    From incubator-datasketches-hive with Apache License 2.0 5 votes vote down vote up
@Test
public void emptySketch() {
  final CpcSketch sketch = new CpcSketch(12);
  final Double result = new GetEstimateUDF().evaluate(new BytesWritable(sketch.toByteArray()));
  Assert.assertNotNull(result);
  Assert.assertEquals(result, 0.0);
}
 
Example 18
Source File: TestZkBaseDataAccessor.java    From helix with Apache License 2.0 4 votes vote down vote up
@Test
public void testSyncUpdate() {
  String className = TestHelper.getTestClassName();
  String methodName = TestHelper.getTestMethodName();
  String testName = className + "_" + methodName;

  System.out.println("START " + testName + " at " + new Date(System.currentTimeMillis()));

  String path = String.format("/%s/%s", _rootPath, "msg_0");
  ZNRecord record = new ZNRecord("msg_0");
  ZkBaseDataAccessor<ZNRecord> accessor = new ZkBaseDataAccessor<ZNRecord>(_gZkClient);

  boolean success = accessor.update(path, new ZNRecordUpdater(record), AccessOption.PERSISTENT);
  Assert.assertTrue(success);
  ZNRecord getRecord = _gZkClient.readData(path);
  Assert.assertNotNull(getRecord);
  Assert.assertEquals(getRecord.getId(), "msg_0");

  record.setSimpleField("key0", "value0");
  success = accessor.update(path, new ZNRecordUpdater(record), AccessOption.PERSISTENT);
  Assert.assertTrue(success);
  getRecord = _gZkClient.readData(path);
  Assert.assertNotNull(getRecord);
  Assert.assertEquals(getRecord.getSimpleFields().size(), 1);
  Assert.assertNotNull(getRecord.getSimpleField("key0"));
  Assert.assertEquals(getRecord.getSimpleField("key0"), "value0");

  // test throw exception from updater
  success = accessor.update(path, new DataUpdater<ZNRecord>() {

    @Override
    public ZNRecord update(ZNRecord currentData) {
      throw new RuntimeException("IGNORABLE: test throw exception from updater");
    }
  }, AccessOption.PERSISTENT);
  Assert.assertFalse(success);
  getRecord = _gZkClient.readData(path);
  Assert.assertNotNull(getRecord);
  Assert.assertEquals(getRecord.getSimpleFields().size(), 1);

  System.out.println("END " + testName + " at " + new Date(System.currentTimeMillis()));
}
 
Example 19
Source File: BasicGrpcTestCase.java    From product-microgateway with Apache License 2.0 4 votes vote down vote up
@Test(description = "Test BasicAuth Grpc Passthrough with transport security")
public void testBasicGrpcPassthrough() throws Exception {
    String response = testGrpcService("localhost:9595", "sample-request");
    Assert.assertNotNull(response);
    Assert.assertEquals(response, "response received :sample-request");
}
 
Example 20
Source File: FairQueueTest.java    From DataHubSystem with GNU Affero General Public License v3.0 4 votes vote down vote up
@Test
public void testPoll2 () throws InterruptedException
{
   Assert.assertEquals (queue.size (), 0);
   FairQueueTestString s = queue.poll (5, TimeUnit.SECONDS);
   Assert.assertNull (s);

   new Thread (new Runnable ()
   {
      @Override
      public void run ()
      {
         try
         {
            Thread.sleep (3000);
         }
         catch (InterruptedException e)
         {
            // TODO Auto-generated catch block
            e.printStackTrace ();
         }
         queue.offer (new FairQueueTestString ("key1", "item1"));
      }
   }).start ();
   s = queue.poll (5, TimeUnit.SECONDS);
   ;
   Assert.assertNotNull (s);
   Assert.assertEquals (s.getItem (), "item1");

   queue.offer (new FairQueueTestString ("key1", "item1"));
   queue.offer (new FairQueueTestString ("key1", "item2"));
   queue.offer (new FairQueueTestString ("key1", "item3"));
   queue.offer (new FairQueueTestString ("key2", "item4"));
   queue.offer (new FairQueueTestString ("key2", "item5"));
   Assert.assertEquals (queue.size (), 5);
   s = queue.poll (5, TimeUnit.SECONDS);
   Assert.assertNotNull (s);
   Assert.assertEquals (s.getItem (), "item1");
   Assert.assertEquals (queue.size (), 4);
   s = queue.poll (5, TimeUnit.SECONDS);
   Assert.assertNotNull (s);
   Assert.assertEquals (s.getItem (), "item4");
   Assert.assertEquals (queue.size (), 3);
}