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

The following are Jave code examples for showing how to use assertNotNull() 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: flow-platform   File: AgentServiceTest.java   View Source Code Vote up 7 votes
@Test
public void should_create_agent_and_send_webhook_if_agent_status_changed() throws Throwable {
    // given: mock agent webhook callback
    String webhook = "http://localhost:8088/agent/callback";
    stubFor(post(urlEqualTo("/agent/callback")).willReturn(aResponse().withStatus(200)));

    // when:
    AgentPath agentPath = new AgentPath("default", "hello-agent");
    agentService.create(agentPath, webhook);

    // then:
    Agent loaded = agentService.find(agentPath);
    Assert.assertNotNull(loaded);
    Assert.assertEquals(agentPath, loaded.getPath());
    Assert.assertEquals(webhook, loaded.getWebhook());
    Assert.assertEquals(AgentStatus.OFFLINE, loaded.getStatus());

    // when: mock agent status changed
    agentService.saveWithStatus(loaded, AgentStatus.IDLE);
    Thread.sleep(1000); // wait for webhook callback

    // then: check webhook is send or not
    CountMatchingStrategy strategy = new CountMatchingStrategy(CountMatchingStrategy.EQUAL_TO, 1);
    verify(strategy, postRequestedFor(urlEqualTo("/agent/callback")));
}
 
Example 2
Project: camunda-task-dispatcher   File: JmsExternalTaskCompleterTest.java   View Source Code Vote up 6 votes
@Test
public void testFail() {
    completer.fail(new Object());

    ArgumentCaptor<Status> statusCaptor = ArgumentCaptor.forClass(Status.class);
    ArgumentCaptor<String> reasonCaptor = ArgumentCaptor.forClass(String.class);
    ArgumentCaptor<String> detailCaptor = ArgumentCaptor.forClass(String.class);
    Mockito.verify(sender, Mockito.atLeastOnce()).send(Mockito.any(), statusCaptor.capture(), reasonCaptor.capture(), detailCaptor.capture());

    Status status = statusCaptor.getAllValues().get(0);
    Assert.assertNotNull(status);
    Assert.assertEquals(Status.FAIL, status);

    String reason = reasonCaptor.getAllValues().get(0);
    Assert.assertNull(reason);

    String detail = detailCaptor.getAllValues().get(0);
    Assert.assertNull(detail);
}
 
Example 3
Project: redirector   File: NamespaceTest.java   View Source Code Vote up 6 votes
@Test
public void testCREATE() throws Exception {


    NamespacedList nmsp = new NamespacedList();
    Set<Value> values  = new LinkedHashSet<>();
    values.add(new Value("test"));
    values.add(new Value("test1"));
    values.add(new Value("test2"));
    values.add(new Value("test3"));
    nmsp.setRet(values);
    List<NamespacedList> namespaceList = new ArrayList<NamespacedList>();
    namespaceList.add(nmsp);
    Namespaces mainNmsp = new Namespaces();
    mainNmsp.setNamespaces(namespaceList);
    final String result = serializeIt(mainNmsp, true);
    System.out.println(result);
    Assert.assertNotNull(result);
}
 
Example 4
Project: rskj   File: MessageTest.java   View Source Code Vote up 6 votes
@Test
public void encodeDecodeBlockHashResponseMessage() {
    long id = 42;
    byte[] hash = new byte[32];
    Random random = new Random();
    random.nextBytes(hash);

    BlockHashResponseMessage message = new BlockHashResponseMessage(id, hash);

    byte[] encoded = message.getEncoded();

    Message result = Message.create(encoded);

    Assert.assertNotNull(result);
    Assert.assertArrayEquals(encoded, result.getEncoded());
    Assert.assertEquals(MessageType.BLOCK_HASH_RESPONSE_MESSAGE, result.getMessageType());

    BlockHashResponseMessage newMessage = (BlockHashResponseMessage) result;

    Assert.assertEquals(id, newMessage.getId());
    Assert.assertArrayEquals(hash, newMessage.getHash());
}
 
Example 5
Project: linkifier   File: RegressionTest.java   View Source Code Vote up 6 votes
@Test
public void test306() throws Throwable {
    if (debug)
        System.out.format("%n%s%n", "RegressionTest0.test306");
    Table table2 = new Table("", ",");
    table2.setTrimmedName("hi!");
    String str5 = table2.getLowerCaseTrimmedName();
    Table[] table_array6 = new Table[] {};
    ArrayList<Table> arraylist_table7 = new ArrayList<Table>();
    boolean b8 = Collections.addAll(arraylist_table7, table_array6);
    List<Table> list_table9 = Optimization.optimize(arraylist_table7);
    Connection connection10 = null;
    List<Table> list_table12 = Schema.getExpensiveFeatures(arraylist_table7, connection10, "");
    table2.isJunctionTable(list_table12);
    List<Table> list_table14 = Optimization.optimize(list_table12);
    double d15 = Accuracy.getPkRecall(list_table14);
    List<Table> list_table16 = Optimization.optimize(list_table14);
    Assert.assertNull(str5);
    Assert.assertNotNull(table_array6);
    Assert.assertTrue(b8 == false);
    Assert.assertNotNull(list_table9);
    Assert.assertNotNull(list_table12);
    Assert.assertNotNull(list_table14);
    Assert.assertEquals(d15, Double.NaN, 0);
    Assert.assertNotNull(list_table16);
}
 
Example 6
Project: NGB-master   File: ToolsControllerTest.java   View Source Code Vote up 6 votes
private void assertSortRequest(FeatureFileSortRequest request, ArgumentMatcher payloadMatcher) throws Exception {
    ResultActions actions = mvc()
            .perform(post(URL_SORT).content(getObjectMapper().writeValueAsString(request))
                    .contentType(EXPECTED_CONTENT_TYPE))
            .andExpect(status().isOk())
            .andExpect(content().contentType(EXPECTED_CONTENT_TYPE))
            .andExpect(jsonPath(JPATH_PAYLOAD).value(payloadMatcher))
            .andExpect(jsonPath(JPATH_STATUS).value(ResultStatus.OK.name()));
    actions.andDo(MockMvcResultHandlers.print());

    final ResponseResult<String> res = getObjectMapper()
            .readValue(actions.andReturn().getResponse().getContentAsByteArray(),
                    getTypeFactory().constructParametrizedType(ResponseResult.class, ResponseResult.class,
                            String.class));

    Assert.assertNotNull(res.getPayload());
}
 
Example 7
Project: GitHub   File: LocalResourceSimpleAdapterTest.java   View Source Code Vote up 5 votes
public void testEagerAdapter() {
  final Context context = getContext();
  final Resources res = context.getResources();
  final String[] uris = res.getStringArray(R.array.local_uri_test);
  Assert.assertNotNull(uris);
  SimpleAdapter<Uri> simpleAdapter = LocalResourceSimpleAdapter
      .getEagerAdapter(context, R.array.local_uri_test);
  checkSimpleAdapterData(simpleAdapter, uris.length);
  Assert.assertFalse(simpleAdapter.isLazy());
}
 
Example 8
Project: apollo-custom   File: ControllerExceptionTest.java   View Source Code Vote up 5 votes
@Test
public void testFindEmpty() {
  when(appService.findAll(any(Pageable.class))).thenReturn(new ArrayList<App>());
  Pageable pageable = new PageRequest(0, 10);
  List<AppDTO> appDTOs = appController.find(null, pageable);
  Assert.assertNotNull(appDTOs);
  Assert.assertEquals(0, appDTOs.size());

  appDTOs = appController.find("", pageable);
  Assert.assertNotNull(appDTOs);
  Assert.assertEquals(0, appDTOs.size());
}
 
Example 9
Project: mapbook-android   File: MapbookTest.java   View Source Code Vote up 5 votes
/**
 * Test that the toolbar title is set correctly
 * @throws Exception
 */
@Test
public void checkIfTitleIsDisplayed() throws Exception{
  Assert.assertNotNull(solo.waitForActivity(MapbookActivity.class, 2000));
  final ActionBar actionBar = mActivityRule.getActivity().getSupportActionBar();
  Assert.assertNotNull(actionBar);
  Assert.assertTrue(solo.waitForText( solo.getString(R.string.title)));
}
 
Example 10
Project: lighthouse   File: PodcastLayoutParserTest.java   View Source Code Vote up 5 votes
@Test
public void shouldGetPodcast() throws IOException, JSONException {
    Podcast podcast;
    try (InputStream stream = getResource("podcasts/podcast-1.html")) {
        PodcastLayoutContent content = parser.parse(0, stream, "UTF-8", RESPONSE_URL);
        podcast = content.getPodcast();
    }
    Assert.assertNotNull(podcast);
    try (InputStream resource = getResource("podcasts/podcast-1.podcast.json")) {
        String json = IOUtils.toString(resource, "UTF-8");
        assertEquals(new JSONObject(json), podcast.toJson());
    }
}
 
Example 11
Project: Twitch-Streamer   File: MessageTest.java   View Source Code Vote up 5 votes
@Test
public void testValidMessageConstruction() {
    String line = ":[email protected] PRIVMSG #mrbean :hey man";
    Message msg = new Message().createMessage(line);
    Assert.assertNotNull(msg);
    Assert.assertEquals(msg.getAuthor(), "andrew");
    Assert.assertEquals(msg.getChannel(), "mrbean");
    Assert.assertEquals(msg.getContent(), "hey man");
}
 
Example 12
Project: GitHub   File: ThrowableDeserializerTest.java   View Source Code Vote up 5 votes
public void test_error2() throws Exception {
    Exception error = null;
    try {
        Assert.assertEquals(null, JSON.parseObject("{}", MyException.class).getMessage());
    } catch (Exception ex) {
        error = ex;
    }
    Assert.assertNotNull(error);
}
 
Example 13
Project: linkifier   File: RegressionTest.java   View Source Code Vote up 5 votes
@Test
public void test179() throws Throwable {
    if (debug)
        System.out.format("%n%s%n", "RegressionTest0.test179");
    Column column2 = new Column(",", "");
    column2.setEstimatedRowCount((int) (byte) 0);
    List<String> list_str5 = column2.getTokenizedLowerCaseTrimmedName();
    column2.setDecimalDigits((int) ' ');
    column2.setTableContainsLob(false);
    String str10 = column2.getName();
    Assert.assertNotNull(list_str5);
    Assert.assertTrue("'" + str10 + "' != '" + "" + "'", str10.equals(""));
}
 
Example 14
Project: apm-client   File: TraceClientFilterTest.java   View Source Code Vote up 5 votes
@Test
public void test() throws Exception {

  TracerTestImpl tracer = new TracerTestImpl();

  TraceClientFilter tcf = new TraceClientFilter();
  tcf.setTracer(tracer);

  MultivaluedMap<String, Object> headerAccess = new MultivaluedHashMap<>();

  ClientRequestContext requestContext = Mockito.mock(ClientRequestContext.class);
  Mockito.when(requestContext.getUri()).thenReturn(new URI("https://example.com:7110/some/path"));
  Mockito.when(requestContext.getMethod()).thenReturn("GET");
  Mockito.when(requestContext.getHeaders()).thenReturn(headerAccess);
  Mockito.when(requestContext.getEntityAnnotations()).thenReturn(new Annotation[]{});
  tcf.filter(requestContext);
  Assert.assertNotNull(tracer.getCurrentSpan());

  ClientResponseContext responseContext = Mockito.mock(ClientResponseContext.class);
  tcf.filter(requestContext, responseContext);
  Assert.assertNull(tracer.getCurrentSpan());

  Span span = tracer.getCapturedSpan();
  Assert.assertEquals("service", span.getService());
  Assert.assertEquals("example.com:7110", span.getResource());
  Assert.assertEquals("GET /some/path", span.getOperation());
  Assert.assertEquals(Long.parseUnsignedLong((String)headerAccess.getFirst(TracerImpl.TRACE_ID)), span.getTraceId());
  Assert.assertEquals(Long.parseUnsignedLong((String)headerAccess.getFirst(TracerImpl.SPAN_ID)), span.getSpanId());
}
 
Example 15
Project: GitHub   File: JSONCreatorTest3.java   View Source Code Vote up 5 votes
public void test_create_error() throws Exception {
    Exception error = null;
    try {
        JSON.parseObject("{\"id\":1001,\"name\":\"wenshao\",\"obj\":{\"$ref\":123}}", Entity.class);
    } catch (JSONException ex) {
        error = ex;
    }
    Assert.assertNotNull(error);
}
 
Example 16
Project: flow-platform   File: CredentialControllerTest.java   View Source Code Vote up 5 votes
@Test
public void should_create_ios_credential() throws Throwable {
    // given: create ios credential
    final String credentialName = "ios-test";

    // set password for p12-3.p12 file
    IosCredentialDetail detail = new IosCredentialDetail();
    detail.getP12s().add(new PasswordFileResource("p12-3.p12", null, "123123"));

    performRequestWith200Status(fileUpload(getUrlForCredential(credentialName))
        .file(createIosP12Part("p12-1.p12"))
        .file(createIosP12Part("p12-2.p12"))
        .file(createIosP12Part("p12-3.p12"))
        .file(createIosProvisionProfilePart("pp1.mobileprovision"))
        .file(createIosProvisionProfilePart("pp2.mobileprovision"))
        .param("detail", detail.toJson())
    );

    // when: load credential after created
    String response = performRequestWith200Status(get(getUrlForCredential(credentialName)));
    Credential credential = Credential.parse(response, Credential.class);
    Assert.assertNotNull(credential);

    // then:
    Assert.assertEquals(credentialName, credential.getName());
    Assert.assertEquals(CredentialType.IOS, credential.getType());
    Assert.assertEquals(IosCredentialDetail.class, credential.getDetail().getClass());

    IosCredentialDetail iosDetail = (IosCredentialDetail) credential.getDetail();
    Assert.assertEquals(3, iosDetail.getP12s().size());
    Assert.assertEquals(2, iosDetail.getProvisionProfiles().size());

    for (PasswordFileResource resource : iosDetail.getP12s()) {
        if (resource.getName().equals("p12-3.p12")) {
            Assert.assertEquals("123123", resource.getPassword());
        }
    }
}
 
Example 17
Project: jee-architecture-domain   File: ChefServiceImplITest.java   View Source Code Vote up 5 votes
@Test
public void shouldDeleteChefs() throws ExecutionException, InterruptedException {

    this.chefService.deleteChefs();

    final RequestAllChefEvent requestAllChefEvent = RequestAllChefEvent.builder().limit(10).page(1).build();

    final CatalogChefEvent catalogChefEvent = this.chefService.getChefs(requestAllChefEvent).get();

    Assert.assertNotNull(catalogChefEvent);
    Assert.assertNotNull(catalogChefEvent.getChefs());
    Assert.assertEquals(catalogChefEvent.getChefs().size(), 0);
    Assert.assertEquals(catalogChefEvent.getTotal(), 0);
}
 
Example 18
Project: NGB-master   File: GffManagerTest.java   View Source Code Vote up 4 votes
@Test
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void testUnmappedGenes() throws InterruptedException, NoSuchAlgorithmException, FeatureIndexException,
                                       IOException, GeneReadingException, HistogramReadingException {
    Chromosome testChr1 = EntityHelper.createNewChromosome();
    testChr1.setName("chr1");
    testChr1.setSize(TEST_CHROMOSOME_SIZE);
    Reference testRef = EntityHelper.createNewReference(testChr1, referenceGenomeManager.createReferenceId());

    referenceGenomeManager.register(testRef);
    Long testRefId = testReference.getId();

    Resource resource = context.getResource("classpath:templates/mrna.sorted.chunk.gtf");

    FeatureIndexedFileRegistrationRequest request = new FeatureIndexedFileRegistrationRequest();
    request.setReferenceId(testRefId);
    request.setPath(resource.getFile().getAbsolutePath());

    GeneFile geneFile = gffManager.registerGeneFile(request);
    Assert.assertNotNull(geneFile);
    Assert.assertNotNull(geneFile.getId());

    Track<Gene> track = new Track<>();
    track.setId(geneFile.getId());
    track.setStartIndex(1);
    track.setEndIndex(TEST_UNMAPPED_END_INDEX);
    track.setChromosome(testChr1);
    track.setScaleFactor(FULL_QUERY_SCALE_FACTOR);

    double time1 = Utils.getSystemTimeMilliseconds();
    Track<Gene> featureList = gffManager.loadGenes(track, false);
    double time2 = Utils.getSystemTimeMilliseconds();
    logger.info("genes loading : {} ms", time2 - time1);
    Assert.assertNotNull(featureList);
    Assert.assertFalse(featureList.getBlocks().isEmpty());
    Assert.assertTrue(featureList.getBlocks().stream().allMatch(g -> !g.isMapped()));

    Track<Gene> smallScaleFactorTrack = new Track<>();
    smallScaleFactorTrack.setId(geneFile.getId());
    smallScaleFactorTrack.setStartIndex(1);
    smallScaleFactorTrack.setEndIndex(TEST_UNMAPPED_END_INDEX);
    smallScaleFactorTrack.setChromosome(testChr1);
    smallScaleFactorTrack.setScaleFactor(SMALL_SCALE_FACTOR);

    time1 = Utils.getSystemTimeMilliseconds();
    featureList = gffManager.loadGenes(smallScaleFactorTrack, false);
    time2 = Utils.getSystemTimeMilliseconds();
    logger.info("genes large scale loading : {} ms", time2 - time1);
    Assert.assertNotNull(featureList);
    Assert.assertFalse(featureList.getBlocks().isEmpty());
    Assert.assertTrue(featureList.getBlocks().stream().allMatch(g -> !g.isMapped()));
    int groupedGenesCount = featureList.getBlocks().stream().collect(Collectors.summingInt(Gene::getFeatureCount));
    logger.debug("{} features total", groupedGenesCount);
    Assert.assertEquals(TEST_FEATURE_COUNT, groupedGenesCount);

    Track<Wig> histogram = new Track<>();
    histogram.setId(geneFile.getId());
    histogram.setChromosome(testChr1);
    histogram.setScaleFactor(1.0);

    gffManager.loadHistogram(histogram);
    Assert.assertFalse(histogram.getBlocks().isEmpty());
}
 
Example 19
Project: fuck_zookeeper   File: ZooKeeperQuotaTest.java   View Source Code Vote up 4 votes
@Test
public void testQuota() throws IOException,
    InterruptedException, KeeperException, Exception {
    final ZooKeeper zk = createClient();
    final String path = "/a/b/v";
    // making sure setdata works on /
    zk.setData("/", "some".getBytes(), -1);
    zk.create("/a", "some".getBytes(), Ids.OPEN_ACL_UNSAFE,
            CreateMode.PERSISTENT);

    zk.create("/a/b", "some".getBytes(), Ids.OPEN_ACL_UNSAFE,
            CreateMode.PERSISTENT);

    zk.create("/a/b/v", "some".getBytes(), Ids.OPEN_ACL_UNSAFE,
            CreateMode.PERSISTENT);

    zk.create("/a/b/v/d", "some".getBytes(), Ids.OPEN_ACL_UNSAFE,
            CreateMode.PERSISTENT);
    ZooKeeperMain.createQuota(zk, path, 5L, 10);

    // see if its set
    String absolutePath = Quotas.quotaZookeeper + path + "/" + Quotas.limitNode;
    byte[] data = zk.getData(absolutePath, false, new Stat());
    StatsTrack st = new StatsTrack(new String(data));
    Assert.assertTrue("bytes are set", st.getBytes() == 5L);
    Assert.assertTrue("num count is set", st.getCount() == 10);

    String statPath = Quotas.quotaZookeeper + path + "/" + Quotas.statNode;
    byte[] qdata = zk.getData(statPath, false, new Stat());
    StatsTrack qst = new StatsTrack(new String(qdata));
    Assert.assertTrue("bytes are set", qst.getBytes() == 8L);
    Assert.assertTrue("count is set", qst.getCount() == 2);

    //force server to restart and load from snapshot, not txn log
    stopServer();
    startServer();
    stopServer();
    startServer();
    ZooKeeperServer server = getServer(serverFactory);
    Assert.assertNotNull("Quota is still set",
        server.getZKDatabase().getDataTree().getMaxPrefixWithQuota(path) != null);
}
 
Example 20
Project: SpringBoot_Wechat_Sell   File: CategoryServiceImplTest.java   View Source Code Vote up 4 votes
@Test
public void findOne() throws Exception {
    ProductCategory productCategory = categoryService.findOne(1);
    Assert.assertNotNull(productCategory);

}