org.hamcrest.collection.IsCollectionWithSize Java Examples

The following examples show how to use org.hamcrest.collection.IsCollectionWithSize. 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 Project: auth0-spring-security-api   Author: auth0   File: AuthenticationJsonWebTokenTest.java    License: MIT License 6 votes vote down vote up
@Test
public void shouldGetScopeAsAuthorities() throws Exception {
    String token = JWT.create()
            .withClaim("scope", "auth0 auth10")
            .sign(hmacAlgorithm);

    AuthenticationJsonWebToken auth = new AuthenticationJsonWebToken(token, verifier);
    assertThat(auth, is(notNullValue()));

    Collection<? extends GrantedAuthority> authorities = auth.getAuthorities();
    assertThat(authorities, is(notNullValue()));
    assertThat(authorities, is(IsCollectionWithSize.hasSize(4)));
    assertThat(authorities, containsInAnyOrder(
            hasProperty("authority", is("auth0")),
            hasProperty("authority", is("auth10")),
            hasProperty("authority", is("SCOPE_auth0")),
            hasProperty("authority", is("SCOPE_auth10"))
    ));
}
 
Example #2
Source Project: auth0-spring-security-api   Author: auth0   File: AuthenticationJsonWebTokenTest.java    License: MIT License 6 votes vote down vote up
@Test
public void shouldGetPermissionsAsAuthorities() throws Exception {
    String[] permissionsClaim = {"read:permission", "write:permission"};
    String token = JWT.create()
            .withArrayClaim("permissions", permissionsClaim)
            .sign(hmacAlgorithm);

    AuthenticationJsonWebToken auth = new AuthenticationJsonWebToken(token, verifier);
    assertThat(auth, is(notNullValue()));
    assertThat(auth.getAuthorities(), is(notNullValue()));
    assertThat(auth.getAuthorities(), is(IsCollectionWithSize.hasSize(2)));

    Collection<? extends GrantedAuthority> authorities = auth.getAuthorities();
    assertThat(authorities, IsCollectionWithSize.hasSize(2));
    assertThat(authorities, containsInAnyOrder(
            hasProperty("authority", is("PERMISSION_" + permissionsClaim[0])),
            hasProperty("authority", is("PERMISSION_" + permissionsClaim[1]))
    ));
}
 
Example #3
Source Project: triplea   Author: triplea-game   File: UserBanServiceTest.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Test
void getBannedUsers() {
  when(userBanDao.lookupBans()).thenReturn(List.of(USER_BAN_RECORD_1, USER_BAN_RECORD_2));

  final List<UserBanData> result = bannedUsersService.getBannedUsers();

  assertThat(result, IsCollectionWithSize.hasSize(2));

  assertThat(result.get(0).getBanDate(), is(USER_BAN_RECORD_1.getDateCreated().toEpochMilli()));
  assertThat(result.get(0).getBanExpiry(), is(USER_BAN_RECORD_1.getBanExpiry().toEpochMilli()));
  assertThat(result.get(0).getBanId(), is(USER_BAN_RECORD_1.getPublicBanId()));
  assertThat(result.get(0).getHashedMac(), is(USER_BAN_RECORD_1.getSystemId()));
  assertThat(result.get(0).getIp(), is(USER_BAN_RECORD_1.getIp()));
  assertThat(result.get(0).getUsername(), is(USER_BAN_RECORD_1.getUsername()));

  assertThat(result.get(1).getBanDate(), is(USER_BAN_RECORD_2.getDateCreated().toEpochMilli()));
  assertThat(result.get(1).getBanExpiry(), is(USER_BAN_RECORD_2.getBanExpiry().toEpochMilli()));
  assertThat(result.get(1).getBanId(), is(USER_BAN_RECORD_2.getPublicBanId()));
  assertThat(result.get(1).getHashedMac(), is(USER_BAN_RECORD_2.getSystemId()));
  assertThat(result.get(1).getIp(), is(USER_BAN_RECORD_2.getIp()));
  assertThat(result.get(1).getUsername(), is(USER_BAN_RECORD_2.getUsername()));
}
 
Example #4
Source Project: triplea   Author: triplea-game   File: GameChatHistoryDaoTest.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Test
void viewChatHistoryForSirHostALotsGame() {
  final List<ChatHistoryRecord> chats = gameChatHistoryDao.getChatHistory("game-hosts-a-lot");

  assertThat(chats, IsCollectionWithSize.hasSize(4));

  int i = 0;
  assertThat(chats.get(i).getUsername(), is(PLAYER1));
  assertThat(chats.get(i).getDate(), isInstant(2100, 1, 1, 23, 0, 20));
  assertThat(chats.get(i).getMessage(), is("Hello good sir"));

  i++;
  assertThat(chats.get(i).getUsername(), is(SIR_HOSTS_A_LOT));
  assertThat(chats.get(i).getDate(), isInstant(2100, 1, 1, 23, 1, 20));
  assertThat(chats.get(i).getMessage(), is("Why hello to you"));

  i++;
  assertThat(chats.get(i).getUsername(), is(PLAYER1));
  assertThat(chats.get(i).getDate(), isInstant(2100, 1, 1, 23, 2, 20));
  assertThat(chats.get(i).getMessage(), is("What a fine day it is my good sir"));

  i++;
  assertThat(chats.get(i).getUsername(), is(SIR_HOSTS_A_LOT));
  assertThat(chats.get(i).getDate(), isInstant(2100, 1, 1, 23, 3, 20));
  assertThat(chats.get(i).getMessage(), is("What a fine day it is indeed!"));
}
 
Example #5
Source Project: triplea   Author: triplea-game   File: GameChatHistoryDaoTest.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Test
void viewChatHistoryForSirHostALittlesGame() {
  final List<ChatHistoryRecord> chats = gameChatHistoryDao.getChatHistory("game-hosts-a-little");

  assertThat(chats, IsCollectionWithSize.hasSize(3));

  int i = 0;
  assertThat(chats.get(i).getUsername(), is(SIR_HOSTS_A_LITTLE));
  assertThat(chats.get(i).getDate(), isInstant(2100, 1, 1, 23, 1, 20));
  assertThat(chats.get(i).getMessage(), is("hello!"));

  i++;
  assertThat(chats.get(i).getUsername(), is(SIR_HOSTS_A_LOT));
  assertThat(chats.get(i).getDate(), isInstant(2100, 1, 1, 23, 2, 20));
  assertThat(chats.get(i).getMessage(), is("join my game?"));

  i++;
  assertThat(chats.get(i).getUsername(), is(SIR_HOSTS_A_LITTLE));
  assertThat(chats.get(i).getDate(), isInstant(2100, 1, 1, 23, 3, 20));
  assertThat(chats.get(i).getMessage(), is("Maybe another day"));
}
 
Example #6
Source Project: docker-workflow-plugin   Author: jenkinsci   File: DockerUtilsTest.java    License: MIT License 6 votes vote down vote up
@Test public void parseBuildArgsOverridingDefaults() throws IOException, InterruptedException {

        Dockerfile dockerfile = getDockerfileDefaultArgs();

        final String registry = "http://private.registry:5000/";
        final String key_registry = "REGISTRY_URL";
        final String key_tag = "TAG";
        final String tag = "1.2.3";
        final String commangLine = "docker build -t hello-world --build-arg "+key_tag+"="+tag+
            " --build-arg "+key_registry+"="+registry;
        Map<String, String> buildArgs = DockerUtils.parseBuildArgs(dockerfile, commangLine);

        Assert.assertThat(buildArgs.keySet(), IsCollectionWithSize.hasSize(2));
        Assert.assertThat(buildArgs.keySet(), IsCollectionContaining.hasItems(key_registry, key_tag));
        Assert.assertThat(buildArgs.get(key_registry), IsEqual.equalTo(registry));
        Assert.assertThat(buildArgs.get(key_tag), IsEqual.equalTo(tag));
    }
 
Example #7
Source Project: java-jwt   Author: auth0   File: PayloadDeserializerTest.java    License: MIT License 6 votes vote down vote up
@Test
public void shouldGetStringArrayWhenParsingArrayNode() throws Exception {
    Map<String, JsonNode> tree = new HashMap<>();
    List<JsonNode> subNodes = new ArrayList<>();
    TextNode textNode1 = new TextNode("one");
    TextNode textNode2 = new TextNode("two");
    subNodes.add(textNode1);
    subNodes.add(textNode2);
    ArrayNode arrNode = new ArrayNode(JsonNodeFactory.instance, subNodes);
    tree.put("key", arrNode);

    List<String> values = deserializer.getStringOrArray(tree, "key");
    assertThat(values, is(notNullValue()));
    assertThat(values, is(IsCollectionWithSize.hasSize(2)));
    assertThat(values, is(IsCollectionContaining.hasItems("one", "two")));
}
 
Example #8
Source Project: tutorials   Author: eugenp   File: PowerSetUtilityUnitTest.java    License: MIT License 6 votes vote down vote up
@Test
public void givenSet_WhenPowerSetIsLazyLoadGenerated_ThenItContainsAllSubsets() {
    Set<String> set = RandomSetOfStringGenerator.generateRandomSet();
    Set<Set<String>> powerSet = new PowerSetUtility<String>().lazyLoadPowerSet(set);

    //To make sure that the size of power set is (2 power n)
    MatcherAssert.assertThat(powerSet, IsCollectionWithSize.hasSize((1 << set.size())));
    //To make sure that number of occurrence of each element is (2 power n-1)
    Map<String, Integer> counter = new HashMap<>();
    for (Set<String> subset : powerSet) {
        for (String name : subset) {
            int num = counter.getOrDefault(name, 0);
            counter.put(name, num + 1);
        }
    }
    counter.forEach((k, v) -> Assertions.assertEquals((1 << (set.size() - 1)), v.intValue()));
}
 
Example #9
Source Project: tutorials   Author: eugenp   File: PowerSetUtilityUnitTest.java    License: MIT License 6 votes vote down vote up
@Test
public void givenSet_WhenPowerSetIsCalculated_ThenItContainsAllSubsets() {
    Set<String> set = RandomSetOfStringGenerator.generateRandomSet();

    Set<Set<String>> powerSet = new PowerSetUtility<String>().recursivePowerSet(set);

    //To make sure that the size of power set is (2 power n)
    MatcherAssert.assertThat(powerSet, IsCollectionWithSize.hasSize((1 << set.size())));
    //To make sure that number of occurrence of each element is (2 power n-1)
    Map<String, Integer> counter = new HashMap<>();
    for (Set<String> subset : powerSet) {
        for (String name : subset) {
            int num = counter.getOrDefault(name, 0);
            counter.put(name, num + 1);
        }
    }
    counter.forEach((k, v) -> Assertions.assertEquals((1 << (set.size() - 1)), v.intValue()));
}
 
Example #10
Source Project: tutorials   Author: eugenp   File: PowerSetUtilityUnitTest.java    License: MIT License 6 votes vote down vote up
@Test
public void givenSet_WhenPowerSetIsCalculatedRecursiveByIndexRepresentation_ThenItContainsAllSubsets() {
    Set<String> set = RandomSetOfStringGenerator.generateRandomSet();

    Set<Set<String>> powerSet = new PowerSetUtility<String>().recursivePowerSetIndexRepresentation(set);

    //To make sure that the size of power set is (2 power n)
    MatcherAssert.assertThat(powerSet, IsCollectionWithSize.hasSize((1 << set.size())));
    //To make sure that number of occurrence of each element is (2 power n-1)
    Map<String, Integer> counter = new HashMap<>();
    for (Set<String> subset : powerSet) {
        for (String name : subset) {
            int num = counter.getOrDefault(name, 0);
            counter.put(name, num + 1);
        }
    }
    counter.forEach((k, v) -> Assertions.assertEquals((1 << (set.size() - 1)), v.intValue()));
}
 
Example #11
Source Project: tutorials   Author: eugenp   File: PowerSetUtilityUnitTest.java    License: MIT License 6 votes vote down vote up
@Test
public void givenSet_WhenPowerSetIsCalculatedRecursiveByBinaryRepresentation_ThenItContainsAllSubsets() {
    Set<String> set = RandomSetOfStringGenerator.generateRandomSet();

    Set<Set<String>> powerSet = new PowerSetUtility<String>().recursivePowerSetBinaryRepresentation(set);

    //To make sure that the size of power set is (2 power n)
    MatcherAssert.assertThat(powerSet, IsCollectionWithSize.hasSize((1 << set.size())));
    //To make sure that number of occurrence of each element is (2 power n-1)
    Map<String, Integer> counter = new HashMap<>();
    for (Set<String> subset : powerSet) {
        for (String name : subset) {
            int num = counter.getOrDefault(name, 0);
            counter.put(name, num + 1);
        }
    }
    counter.forEach((k, v) -> Assertions.assertEquals((1 << (set.size() - 1)), v.intValue()));
}
 
Example #12
Source Project: camunda-bpm-platform   Author: camunda   File: FetchAndLockHandlerTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void shouldResumeAsyncResponseDueToAvailableTasks() {
  // given
  List<LockedExternalTask> tasks = new ArrayList<LockedExternalTask>();
  tasks.add(lockedExternalTaskMock);
  doReturn(tasks).when(fetchTopicBuilder).execute();

  AsyncResponse asyncResponse = mock(AsyncResponse.class);
  handler.addPendingRequest(createDto(5000L), asyncResponse, processEngine);

  // when
  handler.acquire();

  // then
  verify(asyncResponse).resume(argThat(IsCollectionWithSize.hasSize(1)));
  assertThat(handler.getPendingRequests().size(), is(0));
  verify(handler).suspend(Long.MAX_VALUE);
}
 
Example #13
Source Project: camunda-bpm-platform   Author: camunda   File: FetchAndLockHandlerTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void shouldResumeAsyncResponseDueToTimeoutExpired_2() {
  // given
  doReturn(Collections.emptyList()).when(fetchTopicBuilder).execute();

  AsyncResponse asyncResponse = mock(AsyncResponse.class);
  handler.addPendingRequest(createDto(5000L), asyncResponse, processEngine);

  addSecondsToClock(1);
  handler.acquire();

  // assume
  assertThat(handler.getPendingRequests().size(), is(1));
  verify(handler).suspend(4000L);

  addSecondsToClock(4);

  // when
  handler.acquire();

  // then
  verify(asyncResponse).resume(argThat(IsCollectionWithSize.hasSize(0)));
  assertThat(handler.getPendingRequests().size(), is(0));
  verify(handler).suspend(Long.MAX_VALUE);
}
 
Example #14
Source Project: jbang   Author: jbangdev   File: TestRun.java    License: MIT License 5 votes vote down vote up
@Test
void testCreateJar(@TempDir Path rootdir) throws IOException {

	File dir = new File(rootdir.toFile(), "content");

	File basedir = dir.toPath().resolve("a/b/c").toFile();
	boolean mkdirs = basedir.mkdirs();
	assert (mkdirs);
	File classfile = new File(basedir, "mymain.class");
	classfile.setLastModified(System.currentTimeMillis());
	classfile.createNewFile();
	assert (classfile.exists());

	File out = new File(rootdir.toFile(), "content.jar");

	Script s = new Script("", null, null);
	s.setMainClass("wonkabear");
	s.createJarFile(dir, out);

	try (JarFile jf = new JarFile(out)) {

		assertThat(Collections.list(jf.entries()), IsCollectionWithSize.hasSize(5));

		assertThat(jf.getManifest().getMainAttributes().getValue(Attributes.Name.MAIN_CLASS), equalTo("wonkabear"));

		assert (out.exists());
	}

}
 
Example #15
Source Project: appiumpro   Author: cloudgrey-io   File: Edition101_AI_For_Selenium.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testClassifierClient() throws Exception {
    driver.get("https://test.ai");
    List<WebElement> els = classifier.findElementsMatchingLabel(driver, "twitter");
    Assert.assertThat(els, IsCollectionWithSize.hasSize(1));
    els.get(0).click();
    Assert.assertEquals(driver.getCurrentUrl(), "https://twitter.com/testdotai");
}
 
Example #16
Source Project: heimdall   Author: getheimdall   File: RouteSortTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void routeWithWildCardNeedBeTheLast() {

     ZuulRoute r1 = new ZuulRoute("/cartoes", "");
     ZuulRoute r2 = new ZuulRoute("/cartoes/*", "");
     ZuulRoute r3 = new ZuulRoute("/foo", "");
     ZuulRoute r4 = new ZuulRoute("/foo/*", "");
     ZuulRoute r5 = new ZuulRoute("/*", "");
     
     actual.add(r5);
     actual.add(r3);
     actual.add(r2);
     actual.add(r4);
     actual.add(r1);

     expected.add(r1);
     expected.add(r2);
     expected.add(r3);
     expected.add(r4);
     expected.add(r5);

     actual.sort(new RouteSort());

     assertThat(actual, IsCollectionWithSize.hasSize(5));
     assertTrue(actual.get(actual.size() - 1).getPath().startsWith("/*"));
     assertThat(actual, is(expected));
}
 
Example #17
Source Project: vind   Author: RBMHTechnology   File: ServerPojoTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
@RunWithBackend(Solr)
public void testPojoRoundtrip() {
    final SearchServer server = backend.getSearchServer();

    final Pojo doc1 = Pojo.create("doc1", "Eins", "Erstes Dokument", "simple");
    final Pojo doc2 = Pojo.create("doc2", "Zwei", "Zweites Dokument", "simple");
    final Pojo doc3 = Pojo.create("doc3", "Drei", "Dieses ist das dritte Dokument", "complex");
    final Pojo doc4 = Pojo.create("doc3", "Drei", "Dieses ist das dritte Dokument", "complex");

    server.indexBean(doc1);
    server.indexBean(doc2);
    server.indexBean(doc3);
    server.commit();

    final BeanSearchResult<Pojo> dritte = server.execute(Search.fulltext("dritte"), Pojo.class);
    assertThat("#numOfResults", dritte.getNumOfResults(), CoreMatchers.equalTo(1l));
    assertThat("results.size()", dritte.getResults(), IsCollectionWithSize.hasSize(1));
    checkPojo(doc3, dritte.getResults().get(0));

    final BeanSearchResult<Pojo> all = server.execute(Search.fulltext()
            .facet("category")
            .filter(or(eq("title", "Eins"), or(eq("title", "Zwei"),eq("title","Drei"))))
            .sort("_id_", Sort.Direction.Desc), Pojo.class); //TODO create special sort for reserved fields (like score, type, id)
    assertThat("#numOfResults", all.getNumOfResults(), CoreMatchers.equalTo(3l));
    assertThat("results.size()", all.getResults(), IsCollectionWithSize.hasSize(3));
    checkPojo(doc3, all.getResults().get(0));
    checkPojo(doc2, all.getResults().get(1));
    checkPojo(doc1, all.getResults().get(2));

    TermFacetResult<String> facets = all.getFacetResults().getTermFacet("category", String.class);
    assertEquals(2,facets.getValues().size());
    assertEquals("simple", facets.getValues().get(0).getValue());
    assertEquals("complex",facets.getValues().get(1).getValue());
    assertEquals(2,facets.getValues().get(0).getCount());
    assertEquals(1,facets.getValues().get(1).getCount());
}
 
Example #18
Source Project: vind   Author: RBMHTechnology   File: ServerPojoTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
@RunWithBackend(Solr)
public void testMultipleBeanIndex() {
    final SearchServer server = backend.getSearchServer();

    final Pojo doc1 = Pojo.create("doc1", "Eins", "Erstes Dokument", "simple");
    final Pojo doc2 = Pojo.create("doc2", "Zwei", "Zweites Dokument", "simple");
    final Pojo doc3 = Pojo.create("doc3", "Drei", "Dieses ist das dritte Dokument", "complex");
    final Pojo doc4 = Pojo.create("doc4", "Vier", "Das vierte Dokument", "complex");

    server.indexBean(doc1,doc2);

    List<Object> beanList = new ArrayList<>();
    beanList.add(doc3);
    beanList.add(doc4);

    server.indexBean(beanList);
    server.commit();

    final BeanSearchResult<Pojo> all = server.execute(Search.fulltext(), Pojo.class);
    assertThat("#numOfResults", all.getNumOfResults(), CoreMatchers.equalTo(4l));
    assertThat("results.size()", all.getResults(), IsCollectionWithSize.hasSize(4));
    checkPojo(doc3, all.getResults().get(2));
    checkPojo(doc2, all.getResults().get(1));
    checkPojo(doc1, all.getResults().get(0));
    checkPojo(doc4, all.getResults().get(3));
}
 
Example #19
Source Project: carts   Author: microservices-demo   File: UnitCartContentsResource.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void shouldAddAndReturnContents() {
    CartContentsResource contentsResource = new CartContentsResource(fakeDAO, () -> fakeCartResource);
    Item item = new Item("testId");
    contentsResource.add(() -> item).run();
    assertThat(contentsResource.contents().get(), IsCollectionWithSize.hasSize(1));
    assertThat(contentsResource.contents().get(), containsInAnyOrder(item));
}
 
Example #20
Source Project: carts   Author: microservices-demo   File: UnitCartContentsResource.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void shouldDeleteItemFromCart() {
    CartContentsResource contentsResource = new CartContentsResource(fakeDAO, () -> fakeCartResource);
    Item item = new Item("testId");
    contentsResource.add(() -> item).run();
    assertThat(contentsResource.contents().get(), IsCollectionWithSize.hasSize(1));
    assertThat(contentsResource.contents().get(), containsInAnyOrder(item));
    Item item2 = new Item(item.itemId());
    contentsResource.delete(() -> item2).run();
    assertThat(contentsResource.contents().get(), IsCollectionWithSize.hasSize(0));
}
 
Example #21
Source Project: triplea   Author: triplea-game   File: FetchingCacheTest.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Test
void lobbyUriOverride() throws Exception {
  final URI overrideUri = URI.create("http://lobby.overrride");
  ClientSetting.lobbyUriOverride.setValueAndFlush(overrideUri);

  final LiveServers result = fetchingCache.get();

  assertThat(result.getServers(), IsCollectionWithSize.hasSize(1));
  assertThat(result.getServers().get(0).getUri(), is(overrideUri));
}
 
Example #22
Source Project: triplea   Author: triplea-game   File: ToolboxAccessLogClientTest.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Test
void sendErrorReportSuccessCase(@WiremockResolver.Wiremock final WireMockServer server) {
  server.stubFor(
      WireMock.post(ToolboxAccessLogClient.FETCH_ACCESS_LOG_PATH)
          .withHeader(AuthenticationHeaders.API_KEY_HEADER, equalTo(EXPECTED_API_KEY))
          .withRequestBody(
              equalToJson(
                  toJson(
                      AccessLogRequest.builder()
                          .accessLogSearchRequest(
                              AccessLogSearchRequest.builder()
                                  .username("%")
                                  .ip("1.%")
                                  .systemId("123")
                                  .build())
                          .pagingParams(HttpClientTesting.PAGING_PARAMS)
                          .build())))
          .willReturn(
              WireMock.aResponse().withStatus(200).withBody(toJson(List.of(ACCESS_LOG_DATA)))));

  final List<AccessLogData> results =
      newClient(server)
          .getAccessLog(
              AccessLogSearchRequest.builder().username("%").systemId("123").ip("1.%").build(),
              HttpClientTesting.PAGING_PARAMS);

  assertThat(results, IsCollectionWithSize.hasSize(1));
  assertThat(results.get(0), is(ACCESS_LOG_DATA));
}
 
Example #23
Source Project: edison-microservice   Author: otto-de   File: InMemJobRepositoryTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void shouldFindRunningJobsWithoutUpdatedSinceSpecificDate() throws Exception {
    // given
    repository.createOrUpdate(newJobInfo("deadJob", "FOO", fixed(Instant.now().minusSeconds(10), systemDefault()), "localhost"));
    repository.createOrUpdate(newJobInfo("running", "FOO", fixed(Instant.now(), systemDefault()), "localhost"));

    // when
    final List<JobInfo> jobInfos = repository.findRunningWithoutUpdateSince(now().minus(5, ChronoUnit.SECONDS));

    // then
    assertThat(jobInfos, IsCollectionWithSize.hasSize(1));
    assertThat(jobInfos.get(0).getJobId(), is("deadJob"));
}
 
Example #24
Source Project: edison-microservice   Author: otto-de   File: DynamoJobRepositoryTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
void shouldFindRunningJobsWithoutUpdatedSinceSpecificDate() {
    // given
    testee.createOrUpdate(newJobInfo("deadJob", "FOO", fixed(Instant.now().minusSeconds(10), systemDefault()), "localhost"));
    testee.createOrUpdate(newJobInfo("running", "FOO", fixed(Instant.now(), systemDefault()), "localhost"));

    // when
    final List<JobInfo> jobInfos = testee.findRunningWithoutUpdateSince(now().minus(5, ChronoUnit.SECONDS));

    // then
    assertThat(jobInfos, IsCollectionWithSize.hasSize(1));
    assertThat(jobInfos.get(0).getJobId(), is("deadJob"));
}
 
Example #25
Source Project: docker-workflow-plugin   Author: jenkinsci   File: DockerfileTest.java    License: MIT License 5 votes vote down vote up
@Test public void parseDockerfile() throws IOException, InterruptedException {
    Dockerfile dockerfile = new Dockerfile(dockerfilePath);
    Assert.assertThat(dockerfile.getFroms(), IsCollectionWithSize.hasSize(1));
    Assert.assertThat(dockerfile.getFroms().getLast(), IsEqual.equalTo("${REGISTRY_URL}hello-world:${TAG}"));
    Assert.assertThat(dockerfile.getArgs().keySet(), IsCollectionWithSize.hasSize(2));
    Assert.assertThat(dockerfile.getArgs().keySet(), IsCollectionContaining.hasItems("REGISTRY_URL", "TAG"));
}
 
Example #26
Source Project: docker-workflow-plugin   Author: jenkinsci   File: DockerUtilsTest.java    License: MIT License 5 votes vote down vote up
@Test public void parseBuildArgs() throws IOException, InterruptedException {

        FilePath dockerfilePath = new FilePath(new File("src/test/resources/Dockerfile-withArgs"));
        Dockerfile dockerfile = new Dockerfile(dockerfilePath);

        final String imageToUpdate = "hello-world:latest";
        final String key = "IMAGE_TO_UPDATE";
        final String commangLine = "docker build -t hello-world --build-arg "+key+"="+imageToUpdate;
        Map<String, String> buildArgs = DockerUtils.parseBuildArgs(dockerfile, commangLine);

        Assert.assertThat(buildArgs.keySet(), IsCollectionWithSize.hasSize(1));
        Assert.assertThat(buildArgs.keySet(), IsCollectionContaining.hasItems(key));
        Assert.assertThat(buildArgs.get(key), IsEqual.equalTo(imageToUpdate));
    }
 
Example #27
Source Project: docker-workflow-plugin   Author: jenkinsci   File: DockerUtilsTest.java    License: MIT License 5 votes vote down vote up
@Test public void parseBuildArgsWithDefaults() throws IOException, InterruptedException {

        Dockerfile dockerfile = getDockerfileDefaultArgs();

        final String registry = "";
        final String key_registry = "REGISTRY_URL";
        final String key_tag = "TAG";
        final String commangLine = "docker build -t hello-world";
        Map<String, String> buildArgs = DockerUtils.parseBuildArgs(dockerfile, commangLine);

        Assert.assertThat(buildArgs.keySet(), IsCollectionWithSize.hasSize(2));
        Assert.assertThat(buildArgs.keySet(), IsCollectionContaining.hasItems(key_registry, key_tag));
        Assert.assertThat(buildArgs.get(key_registry), IsEqual.equalTo(registry));
        Assert.assertThat(buildArgs.get(key_tag), IsEqual.equalTo("latest"));
    }
 
Example #28
Source Project: docker-workflow-plugin   Author: jenkinsci   File: DockerUtilsTest.java    License: MIT License 5 votes vote down vote up
@Test public void parseBuildArgWithKeyAndEqual() throws IOException, InterruptedException {
    final String commangLine = "docker build -t hello-world --build-arg key=";

    Map<String, String> buildArgs = DockerUtils.parseBuildArgs(null, commangLine);

    Assert.assertThat(buildArgs.keySet(), IsCollectionWithSize.hasSize(1));
    Assert.assertThat(buildArgs.keySet(), IsCollectionContaining.hasItems("key"));
    Assert.assertThat(buildArgs.get("key"), IsEqual.equalTo(""));
}
 
Example #29
Source Project: java-jwt   Author: auth0   File: PayloadDeserializerTest.java    License: MIT License 5 votes vote down vote up
@Test
public void shouldGetStringArrayWhenParsingTextNode() throws Exception {
    Map<String, JsonNode> tree = new HashMap<>();
    TextNode textNode = new TextNode("something");
    tree.put("key", textNode);

    List<String> values = deserializer.getStringOrArray(tree, "key");
    assertThat(values, is(notNullValue()));
    assertThat(values, is(IsCollectionWithSize.hasSize(1)));
    assertThat(values, is(IsCollectionContaining.hasItems("something")));
}
 
Example #30
Source Project: java-jwt   Author: auth0   File: PayloadImplTest.java    License: MIT License 5 votes vote down vote up
@Test
public void shouldGetAudience() throws Exception {
    assertThat(payload, is(notNullValue()));

    assertThat(payload.getAudience(), is(IsCollectionWithSize.hasSize(1)));
    assertThat(payload.getAudience(), is(IsCollectionContaining.hasItems("audience")));
}