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 File: FetchAndLockHandlerTest.java    From camunda-bpm-platform with 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 #2
Source File: FetchAndLockHandlerTest.java    From camunda-bpm-platform with 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 #3
Source File: AuthenticationJsonWebTokenTest.java    From auth0-spring-security-api with 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 #4
Source File: AuthenticationJsonWebTokenTest.java    From auth0-spring-security-api with 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 #5
Source File: PowerSetUtilityUnitTest.java    From tutorials with 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 #6
Source File: PowerSetUtilityUnitTest.java    From tutorials with 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 #7
Source File: PowerSetUtilityUnitTest.java    From tutorials with 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 #8
Source File: PowerSetUtilityUnitTest.java    From tutorials with 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 File: DockerUtilsTest.java    From docker-workflow-plugin with 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 #10
Source File: PayloadDeserializerTest.java    From java-jwt with 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 #11
Source File: GameChatHistoryDaoTest.java    From triplea with 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 #12
Source File: GameChatHistoryDaoTest.java    From triplea with 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 #13
Source File: UserBanServiceTest.java    From triplea with 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 #14
Source File: DockerUtilsTest.java    From docker-workflow-plugin with 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 #15
Source File: DynamoJobRepositoryTest.java    From edison-microservice with 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 #16
Source File: DockerUtilsTest.java    From docker-workflow-plugin with 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 #17
Source File: PayloadDeserializerTest.java    From java-jwt with 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 #18
Source File: PayloadImplTest.java    From java-jwt with 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")));
}
 
Example #19
Source File: JWTDecoderTest.java    From java-jwt with MIT License 5 votes vote down vote up
@Test
public void shouldGetArrayAudience() throws Exception {
    DecodedJWT jwt = JWT.decode("eyJhbGciOiJIUzI1NiJ9.eyJhdWQiOlsiSG9wZSIsIlRyYXZpcyIsIlNvbG9tb24iXX0.Tm4W8WnfPjlmHSmKFakdij0on2rWPETpoM7Sh0u6-S4");
    assertThat(jwt, is(notNullValue()));
    assertThat(jwt.getAudience(), is(IsCollectionWithSize.hasSize(3)));
    assertThat(jwt.getAudience(), is(IsCollectionContaining.hasItems("Hope", "Travis", "Solomon")));
}
 
Example #20
Source File: JWTDecoderTest.java    From java-jwt with MIT License 5 votes vote down vote up
@Test
public void shouldGetStringAudience() throws Exception {
    DecodedJWT jwt = JWT.decode("eyJhbGciOiJIUzI1NiJ9.eyJhdWQiOiJKYWNrIFJleWVzIn0.a4I9BBhPt1OB1GW67g2P1bEHgi6zgOjGUL4LvhE9Dgc");
    assertThat(jwt, is(notNullValue()));
    assertThat(jwt.getAudience(), is(IsCollectionWithSize.hasSize(1)));
    assertThat(jwt.getAudience(), is(IsCollectionContaining.hasItems("Jack Reyes")));
}
 
Example #21
Source File: JWTTest.java    From java-jwt with MIT License 5 votes vote down vote up
@Test
public void shouldGetArrayAudience() throws Exception {
    String token = "eyJhbGciOiJIUzI1NiJ9.eyJhdWQiOlsiSG9wZSIsIlRyYXZpcyIsIlNvbG9tb24iXX0.Tm4W8WnfPjlmHSmKFakdij0on2rWPETpoM7Sh0u6-S4";
    DecodedJWT jwt = JWT.require(Algorithm.HMAC256("secret"))
            .build()
            .verify(token);

    assertThat(jwt, is(notNullValue()));
    assertThat(jwt.getAudience(), is(IsCollectionWithSize.hasSize(3)));
    assertThat(jwt.getAudience(), is(IsCollectionContaining.hasItems("Hope", "Travis", "Solomon")));
}
 
Example #22
Source File: JWTTest.java    From java-jwt with MIT License 5 votes vote down vote up
@Test
public void shouldGetStringAudience() throws Exception {
    String token = "eyJhbGciOiJIUzI1NiJ9.eyJhdWQiOiJKYWNrIFJleWVzIn0.a4I9BBhPt1OB1GW67g2P1bEHgi6zgOjGUL4LvhE9Dgc";
    DecodedJWT jwt = JWT.require(Algorithm.HMAC256("secret"))
            .build()
            .verify(token);

    assertThat(jwt, is(notNullValue()));
    assertThat(jwt.getAudience(), is(IsCollectionWithSize.hasSize(1)));
    assertThat(jwt.getAudience(), is(IsCollectionContaining.hasItems("Jack Reyes")));
}
 
Example #23
Source File: CreateSecretCmdExecIT.java    From docker-java with Apache License 2.0 5 votes vote down vote up
@Test
public void testCreateSecret() throws Exception {
    DockerClient dockerClient = startSwarm();
    int length = 10;
    boolean useLetters = true;
    boolean useNumbers = false;
    String secretName = RandomStringUtils.random(length, useLetters, useNumbers);
    CreateSecretResponse exec = dockerClient.createSecretCmd(new SecretSpec().withName(secretName).withData("mon secret en clair")).exec();
    assertThat(exec, notNullValue());
    assertThat(exec.getId(), notNullValue());
    LOG.info("Secret created with ID {}", exec.getId());


    List<Secret> secrets = dockerClient.listSecretsCmd()
            .withNameFilter(Lists.newArrayList(secretName))
            .exec();

    assertThat(secrets, IsCollectionWithSize.hasSize(1));

    dockerClient.removeSecretCmd(secrets.get(0).getId())
            .exec();
    LOG.info("Secret removed with ID {}", exec.getId());
    List<Secret> secretsAfterRemoved = dockerClient.listSecretsCmd()
            .withNameFilter(Lists.newArrayList(secretName))
            .exec();

    assertThat(secretsAfterRemoved, IsCollectionWithSize.hasSize(0));
}
 
Example #24
Source File: FetchAndLockHandlerTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldResumeAsyncResponseDueToTimeoutExpired_1() {
  // given
  doReturn(Collections.emptyList()).when(fetchTopicBuilder).execute();

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

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

  List<LockedExternalTask> tasks = new ArrayList<LockedExternalTask>();
  tasks.add(lockedExternalTaskMock);
  doReturn(tasks).when(fetchTopicBuilder).execute();

  addSecondsToClock(5);

  // when
  handler.acquire();

  // then
  verify(asyncResponse).resume(argThat(IsCollectionWithSize.hasSize(1)));
  assertThat(handler.getPendingRequests().size(), is(0));
  verify(handler).suspend(Long.MAX_VALUE);
}
 
Example #25
Source File: UnitCartContentsResource.java    From carts with 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 #26
Source File: Edition101_AI_For_Selenium.java    From appiumpro with 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 #27
Source File: RouteSortTest.java    From heimdall with 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 #28
Source File: ServerPojoTest.java    From vind with 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 #29
Source File: ServerPojoTest.java    From vind with 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 #30
Source File: DockerUtilsTest.java    From docker-workflow-plugin with 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));
    }