Java Code Examples for org.mockito.internal.util.collections.Sets#newSet()

The following examples show how to use org.mockito.internal.util.collections.Sets#newSet() . 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: Issue340Test.java    From cron-utils with Apache License 2.0 6 votes vote down vote up
@Test
public void testDayOfWeekRollover() {
    // Every Friday to Tuesday (Fri, Sat, Sun, Mon, Tue) at 5 AM
    String schedule = "0 0 5 ? * FRI-TUE *";
    // Java DayOfWeek is MON (1) to SUN (7)
    Set<Integer> validDaysOfWeek = Sets.newSet(1, 2, 5, 6, 7);
    CronDefinition cronDefinition = CronDefinitionBuilder.instanceDefinitionFor(QUARTZ);
    CronParser parser = new CronParser(cronDefinition);
    Cron quartzCron = parser.parse(schedule);

    ZonedDateTime time = ZonedDateTime.now();
    ExecutionTime executionTime = ExecutionTime.forCron(quartzCron);

    // Check the next 100 execution times
    for (int i = 0; i < 100; i++) {
        Optional<ZonedDateTime> nextExecution = executionTime.nextExecution(time);
        Assert.assertTrue(nextExecution.isPresent());
        time = nextExecution.get();
        int dayOfWeek = time.getDayOfWeek().getValue();
        Assert.assertTrue(validDaysOfWeek.contains(dayOfWeek));
        Assert.assertEquals(5, time.getHour());
        Assert.assertEquals(0, time.getMinute());
        Assert.assertEquals(0, time.getSecond());
    }
}
 
Example 2
Source File: DynamoDbTemplateIntegrationTest.java    From Cheddar with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldUpdate_withSingleItem() {
    // Given
    final DynamoDbTemplate dynamoDbTemplate = new DynamoDbTemplate(databaseSchemaHolder);
    dynamoDbTemplate.initialize(amazonDynamoDbClient);
    final StubItem createdItem = dataGenerator.createStubItem();
    final Long originalVersion = createdItem.getVersion();
    final String stringProperty = randomString(10);
    final String stringProperty2 = randomString(10);
    final Set<String> newStringSetProperty = Sets.newSet(randomString(10), randomString(10), randomString(10));
    createdItem.setStringProperty(stringProperty);
    createdItem.setStringProperty2(stringProperty2);
    createdItem.setStringSetProperty(newStringSetProperty);
    final Long newVersion = originalVersion + 1;

    // When
    final StubItem updatedItem = dynamoDbTemplate.update(createdItem);

    // Then
    assertEquals(newVersion, updatedItem.getVersion());
    assertEquals(createdItem.getId(), updatedItem.getId());
    assertEquals(stringProperty, updatedItem.getStringProperty());
    assertEquals(stringProperty2, updatedItem.getStringProperty2());
    assertEquals(newStringSetProperty, updatedItem.getStringSetProperty());
}
 
Example 3
Source File: ConditionTest.java    From Cheddar with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldReturnDoesNotHaveMissingComparisonValues_withConditionWhichDoesNotRequireComparisonValuesAndNonNullOrEmptyValues() {
    // Given
    final Set<Operators> operatorsWhichDoNotRequireNonNullOrEmptyValues = Sets.newSet(Operators.NOT_NULL,
            Operators.NULL);
    final Operators operatorWhichRequiresNonNullOrEmptyValue = randomEnumInSet(
            operatorsWhichDoNotRequireNonNullOrEmptyValues);
    final String value = randomString();

    final Condition condition = new Condition(operatorWhichRequiresNonNullOrEmptyValue, value);

    // When
    final boolean hasMissingComparisonValues = condition.hasMissingComparisonValues();

    // Then
    assertFalse(hasMissingComparisonValues);
}
 
Example 4
Source File: ConditionTest.java    From Cheddar with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldReturnDoesNotHaveMissingComparisonValues_withConditionWhichRequiresComparisonValuesAndNonNullOrEmptyValues() {
    // Given
    final Set<Operators> operatorsWhichRequireNonNullOrEmptyValues = Sets.newSet(Operators.EQUALS,
            Operators.GREATER_THAN_OR_EQUALS, Operators.LESS_THAN_OR_EQUALS);
    final Operators operatorWhichRequiresNonNullOrEmptyValue = randomEnumInSet(
            operatorsWhichRequireNonNullOrEmptyValues);
    final String value = randomString(10);

    final Condition condition = new Condition(operatorWhichRequiresNonNullOrEmptyValue, value);

    // When
    final boolean hasMissingComparisonValues = condition.hasMissingComparisonValues();

    // Then
    assertFalse(hasMissingComparisonValues);
}
 
Example 5
Source File: ConditionTest.java    From Cheddar with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldReturnHasMissingComparisonValues_withConditionWhichRequiresComparisonValuesAndNullOrEmptyValues() {
    // Given
    final Set<Operators> operatorsWhichRequireNonNullOrEmptyValues = Sets.newSet(Operators.EQUALS,
            Operators.GREATER_THAN_OR_EQUALS, Operators.LESS_THAN_OR_EQUALS);
    final Operators operatorWhichRequiresNonNullOrEmptyValue = randomEnumInSet(
            operatorsWhichRequireNonNullOrEmptyValues);
    final String value = randomBoolean() ? null : "";

    final Condition condition = new Condition(operatorWhichRequiresNonNullOrEmptyValue, value);

    // When
    final boolean hasMissingComparisonValues = condition.hasMissingComparisonValues();

    // Then
    assertTrue(hasMissingComparisonValues);
}
 
Example 6
Source File: ItemHashUtilTest.java    From sakai with Educational Community License v2.0 6 votes vote down vote up
@Test
public void testHashBaseForItemAnswersPreservesNullsLiterally()
        throws IOException, NoSuchAlgorithmException, ServerOverloadException {
    final ItemData item = new ItemData();
    item.setTypeId(TypeIfc.FILL_IN_BLANK);

    // sequence, at least, is required, else ordering is completely non-deterministic
    final Pair<Answer,String> answer1 = answerAndExpectedHashBaseFor(item, 1L, null, null, null, null, null, null);
    final Pair<Answer,String> answer2 = answerAndExpectedHashBaseFor(item, 2L, null, null, null, null, null, null);

    final ItemText itemText1 = new ItemText(item, 1L, null, Sets.newSet(answerFrom(answer1), answerFrom(answer2)));
    answerFrom(answer1).setItemText(itemText1);
    answerFrom(answer2).setItemText(itemText1);

    item.setItemTextSet(Sets.newSet(itemText1));

    final StringBuilder expectedHashBase = new StringBuilder()
            .append(stringFrom(answer1))
            .append(stringFrom(answer2));

    final StringBuilder actualHashBase = new StringBuilder();
    itemHashUtil.hashBaseForItemAnswers(item, actualHashBase);
    assertThat(actualHashBase.toString(), equalTo(expectedHashBase.toString()));
}
 
Example 7
Source File: ItemHashUtilTest.java    From sakai with Educational Community License v2.0 6 votes vote down vote up
@Test
public void testHashBaseForItemAnswersPreservesNullsLiterally()
        throws IOException, NoSuchAlgorithmException, ServerOverloadException {
    final ItemData item = new ItemData();
    item.setTypeId(TypeIfc.FILL_IN_BLANK);

    // sequence, at least, is required, else ordering is completely non-deterministic
    final Pair<Answer,String> answer1 = answerAndExpectedHashBaseFor(item, 1L, null, null, null, null, null, null);
    final Pair<Answer,String> answer2 = answerAndExpectedHashBaseFor(item, 2L, null, null, null, null, null, null);

    final ItemText itemText1 = new ItemText(item, 1L, null, Sets.newSet(answerFrom(answer1), answerFrom(answer2)));
    answerFrom(answer1).setItemText(itemText1);
    answerFrom(answer2).setItemText(itemText1);

    item.setItemTextSet(Sets.newSet(itemText1));

    final StringBuilder expectedHashBase = new StringBuilder()
            .append(stringFrom(answer1))
            .append(stringFrom(answer2));

    final StringBuilder actualHashBase = new StringBuilder();
    itemHashUtil.hashBaseForItemAnswers(item, actualHashBase);
    assertThat(actualHashBase.toString(), equalTo(expectedHashBase.toString()));
}
 
Example 8
Source File: InMemoryDatabaseTemplateTest.java    From Cheddar with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldUpdate_withSingleItemWithCompoundPk() {
    // Given
    final InMemoryDatabaseTemplate databaseTemplate = new InMemoryDatabaseTemplate(databaseSchemaHolder);
    final StubWithRangeItem createdItem = dataGenerator.randomStubWithRangeItem();
    databaseTemplate.create(createdItem);
    final Long originalVersion = createdItem.getVersion();
    final String stringProperty = randomString(10);
    final boolean booleanProperty = randomBoolean();
    final Set<String> newStringSetProperty = Sets.newSet(randomString(10), randomString(10), randomString(10));
    createdItem.setStringProperty(stringProperty);
    createdItem.setBooleanProperty(booleanProperty);
    createdItem.setStringSetProperty(newStringSetProperty);
    final Long newVersion = originalVersion + 1;

    // When
    final StubWithRangeItem updatedItem = databaseTemplate.update(createdItem);

    // Then
    assertEquals(newVersion, updatedItem.getVersion());
    assertEquals(createdItem.getId(), updatedItem.getId());
    assertEquals(stringProperty, updatedItem.getStringProperty());
    assertEquals(booleanProperty, updatedItem.isBooleanProperty());
    assertEquals(newStringSetProperty, updatedItem.getStringSetProperty());
}
 
Example 9
Source File: SessionContainerTest.java    From azure-cosmosdb-java with MIT License 6 votes vote down vote up
@Test(groups = "unit")
public void resolveGlobalSessionTokenReturnsTokenMapUsingResourceId() {
    SessionContainer sessionContainer = new SessionContainer("127.0.0.1");
    String documentCollectionId = ResourceId.newDocumentCollectionId(getRandomDbId(), getRandomCollectionId()).getDocumentCollectionId().toString();
    String collectionFullName = "dbs/db1/colls1/collName";
    RxDocumentServiceRequest request = RxDocumentServiceRequest.create(OperationType.Read,
            documentCollectionId, ResourceType.Document, new HashMap<>());

    sessionContainer.setSessionToken(documentCollectionId, collectionFullName,
            ImmutableMap.of(HttpConstants.HttpHeaders.SESSION_TOKEN, "range_0:1#100#1=20#2=5#3=30"));
    sessionContainer.setSessionToken(documentCollectionId, collectionFullName,
            ImmutableMap.of(HttpConstants.HttpHeaders.SESSION_TOKEN, "range_1:1#101#1=20#2=5#3=30"));
    String sessionToken = sessionContainer.resolveGlobalSessionToken(request);

    Set<String> tokens = Sets.newSet(sessionToken.split(","));
    assertThat(tokens.size()).isEqualTo(2);
    assertThat(tokens.contains("range_0:1#100#1=20#2=5#3=30")).isTrue();
    assertThat(tokens.contains("range_1:1#101#1=20#2=5#3=30")).isTrue();
}
 
Example 10
Source File: SessionContainerTest.java    From azure-cosmosdb-java with MIT License 6 votes vote down vote up
@Test(groups = "unit")
public void resolveGlobalSessionTokenReturnsTokenMapUsingName() {
    SessionContainer sessionContainer = new SessionContainer("127.0.0.1");
    String documentCollectionId = ResourceId.newDocumentCollectionId(getRandomDbId(), getRandomCollectionId()).getDocumentCollectionId().toString();
    String collectionFullName = "dbs/db1/colls1/collName";

    sessionContainer.setSessionToken(documentCollectionId, collectionFullName,
            ImmutableMap.of(HttpConstants.HttpHeaders.SESSION_TOKEN, "range_0:1#100#1=20#2=5#3=30"));
    sessionContainer.setSessionToken(documentCollectionId, collectionFullName,
            ImmutableMap.of(HttpConstants.HttpHeaders.SESSION_TOKEN, "range_1:1#101#1=20#2=5#3=30"));

    RxDocumentServiceRequest request = RxDocumentServiceRequest.createFromName(OperationType.Read,
            collectionFullName + "/docs/doc1", ResourceType.Document);
    String sessionToken = sessionContainer.resolveGlobalSessionToken(request);
    Set<String> tokens = Sets.newSet(sessionToken.split(","));

    assertThat(tokens.size()).isEqualTo(2);
    assertThat(tokens.contains("range_0:1#100#1=20#2=5#3=30")).isTrue();
    assertThat(tokens.contains("range_1:1#101#1=20#2=5#3=30")).isTrue();
}
 
Example 11
Source File: ItemHashUtilTest.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
@Test
public void testHashBaseForItemAnswersNormalizesEmbeddedResourceUrls()
        throws NoSuchAlgorithmException, IOException, ServerOverloadException, IdUnusedException, TypeException,
        PermissionException {

    final ItemData item = new ItemData();
    item.setTypeId(TypeIfc.FILL_IN_BLANK);

    final Pair<Answer,String> answer1 = answerAndExpectedHashBaseFor(item, 1L, true, "Label 1", CONTENT_RESOURCES[0], CONTENT_RESOURCES[1], CONTENT_RESOURCES[2], CONTENT_RESOURCES[3]);
    final Pair<Answer,String> answer2 = answerAndExpectedHashBaseFor(item, 2L, false, "Label 2", CONTENT_RESOURCES[4], CONTENT_RESOURCES[5], CONTENT_RESOURCES[6], CONTENT_RESOURCES[7]);
    final Pair<Answer,String> answer3 = answerAndExpectedHashBaseFor(item, 3L, true, "Label 3", CONTENT_RESOURCES[8], CONTENT_RESOURCES[9], CONTENT_RESOURCES[10], CONTENT_RESOURCES[11]);
    final Pair<Answer,String> answer4 = answerAndExpectedHashBaseFor(item, 4L, false, "Label 4", CONTENT_RESOURCES[12], CONTENT_RESOURCES[13], CONTENT_RESOURCES[14], CONTENT_RESOURCES[15]);

    final ItemText itemText1 = new ItemText(item, 1L, null, Sets.newSet(answerFrom(answer1), answerFrom(answer2)));
    answerFrom(answer1).setItemText(itemText1);
    answerFrom(answer2).setItemText(itemText1);

    final ItemText itemText2 = new ItemText(item, 2L, null, Sets.newSet(answerFrom(answer3), answerFrom(answer4)));
    answerFrom(answer3).setItemText(itemText2);
    answerFrom(answer4).setItemText(itemText2);

    item.setItemTextSet(Sets.newSet(itemText1, itemText2));

    final StringBuilder expectedHashBase = new StringBuilder()
            .append(stringFrom(answer1))
            .append(stringFrom(answer2))
            .append(stringFrom(answer3))
            .append(stringFrom(answer4));

    expectServerUrlLookup();
    IntStream.rangeClosed(0, 15).forEach(
            i -> expectResourceLookupUnchecked(CONTENT_RESOURCES[i])
    );

    final StringBuilder actualHashBase = new StringBuilder();
    itemHashUtil.hashBaseForItemAnswers(item, actualHashBase);
    assertThat(actualHashBase.toString(), equalTo(expectedHashBase.toString()));
}
 
Example 12
Source File: SerializationTest.java    From pravega with Apache License 2.0 5 votes vote down vote up
@Test
public void hostContainerMapTest() {
    Host host = new Host("1.1.1.1", 1234, "ep");
    Host host2 = new Host("1.1.1.2", 1234, "ep");
    ContainerSet set = new ContainerSet(Sets.newSet(1, 2, 3, 4));
    ContainerSet set2 = new ContainerSet(Sets.newSet(1, 2, 3, 4));
    Map<Host, ContainerSet> map = new HashMap<>();
    map.put(host, set);
    map.put(host2, set2);
    HostContainerMap hostContainerMap = new HostContainerMap(map);
    byte[] serialized = hostContainerMap.toBytes();
    HostContainerMap deserialized = HostContainerMap.fromBytes(serialized);
    assertTrue(Maps.difference(hostContainerMap.getHostContainerMap(), deserialized.getHostContainerMap()).areEqual());
}
 
Example 13
Source File: DynamoDbTemplateTest.java    From Cheddar with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldRead_withItemIdAndItemClass() throws Exception {
    // Given
    final ItemId itemId = new ItemId(randomId());

    final ItemConfiguration itemConfiguration = new ItemConfiguration(StubItem.class, tableName);
    final Collection<ItemConfiguration> itemConfigurations = Arrays.asList(itemConfiguration);
    when(mockDatabaseSchemaHolder.itemConfigurations()).thenReturn(itemConfigurations);
    final GetItemResult mockGetItemResult = mock(GetItemResult.class);
    final String stringProperty = randomString(10);
    final String stringProperty2 = randomString(10);
    final Set<String> stringSetProperty = Sets.newSet(randomString(10), randomString(10), randomString(10));
    final Map<String, AttributeValue> itemAttributeMap = new HashMap<>();
    itemAttributeMap.put("id", new AttributeValue(itemId.value()));
    itemAttributeMap.put("stringProperty", new AttributeValue(stringProperty));
    itemAttributeMap.put("stringProperty2", new AttributeValue(stringProperty2));
    itemAttributeMap.put("stringSetProperty", new AttributeValue().withSS(stringSetProperty));
    when(mockGetItemResult.getItem()).thenReturn(itemAttributeMap);
    when(mockAmazonDynamoDbClient.getItem(any(GetItemRequest.class))).thenReturn(mockGetItemResult);

    final DynamoDbTemplate dynamoDbTemplate = new DynamoDbTemplate(mockDatabaseSchemaHolder);
    dynamoDbTemplate.initialize(mockAmazonDynamoDbClient);

    // When
    final StubItem returnedItem = dynamoDbTemplate.read(itemId, StubItem.class);

    // Then
    final ArgumentCaptor<GetItemRequest> getItemRequestCaptor = ArgumentCaptor.forClass(GetItemRequest.class);
    verify(mockAmazonDynamoDbClient).getItem(getItemRequestCaptor.capture());
    assertEquals(itemId.value(), getItemRequestCaptor.getValue().getKey().get("id").getS());
    assertEquals(itemId.value(), returnedItem.getId());
    assertEquals(stringProperty, returnedItem.getStringProperty());
    assertEquals(stringProperty2, returnedItem.getStringProperty2());
    assertEquals(stringSetProperty, returnedItem.getStringSetProperty());
}
 
Example 14
Source File: JournalStoreTest.java    From journalkeeper with Apache License 2.0 5 votes vote down vote up
@Ignore
@Test
public void writePerformanceTest() throws Exception {
    Set<Integer> partitions = Sets.newSet(0, 1, 2, 3, 4);
    Properties properties = new Properties();
    properties.setProperty("cache_requests", String.valueOf(10L * 1024));
    properties.setProperty("enable_events", String.valueOf(false));
    properties.setProperty("print_state_interval_sec", String.valueOf(5));
    properties.setProperty("enable_metric", String.valueOf(true));
    properties.setProperty("print_metric_interval_sec", String.valueOf(5));
    properties.setProperty("replication_batch_size", String.valueOf( 1024));

    writeReadTest(2, partitions,1024, 10, 2L * 1024 * 1024 * 1024, true, ResponseConfig.RECEIVE, false, properties);
}
 
Example 15
Source File: ItemHashUtilTest.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
@Test
public void testHashBaseForItemAnswersNormalizesEmbeddedResourceUrls()
        throws NoSuchAlgorithmException, IOException, ServerOverloadException, IdUnusedException, TypeException,
        PermissionException {

    final ItemData item = new ItemData();
    item.setTypeId(TypeIfc.FILL_IN_BLANK);

    final Pair<Answer,String> answer1 = answerAndExpectedHashBaseFor(item, 1L, true, "Label 1", CONTENT_RESOURCES[0], CONTENT_RESOURCES[1], CONTENT_RESOURCES[2], CONTENT_RESOURCES[3]);
    final Pair<Answer,String> answer2 = answerAndExpectedHashBaseFor(item, 2L, false, "Label 2", CONTENT_RESOURCES[4], CONTENT_RESOURCES[5], CONTENT_RESOURCES[6], CONTENT_RESOURCES[7]);
    final Pair<Answer,String> answer3 = answerAndExpectedHashBaseFor(item, 3L, true, "Label 3", CONTENT_RESOURCES[8], CONTENT_RESOURCES[9], CONTENT_RESOURCES[10], CONTENT_RESOURCES[11]);
    final Pair<Answer,String> answer4 = answerAndExpectedHashBaseFor(item, 4L, false, "Label 4", CONTENT_RESOURCES[12], CONTENT_RESOURCES[13], CONTENT_RESOURCES[14], CONTENT_RESOURCES[15]);

    final ItemText itemText1 = new ItemText(item, 1L, null, Sets.newSet(answerFrom(answer1), answerFrom(answer2)));
    answerFrom(answer1).setItemText(itemText1);
    answerFrom(answer2).setItemText(itemText1);

    final ItemText itemText2 = new ItemText(item, 2L, null, Sets.newSet(answerFrom(answer3), answerFrom(answer4)));
    answerFrom(answer3).setItemText(itemText2);
    answerFrom(answer4).setItemText(itemText2);

    item.setItemTextSet(Sets.newSet(itemText1, itemText2));

    final StringBuilder expectedHashBase = new StringBuilder()
            .append(stringFrom(answer1))
            .append(stringFrom(answer2))
            .append(stringFrom(answer3))
            .append(stringFrom(answer4));

    expectServerUrlLookup();
    IntStream.rangeClosed(0, 15).forEach(
            i -> expectResourceLookupUnchecked(CONTENT_RESOURCES[i])
    );

    final StringBuilder actualHashBase = new StringBuilder();
    itemHashUtil.hashBaseForItemAnswers(item, actualHashBase);
    assertThat(actualHashBase.toString(), equalTo(expectedHashBase.toString()));
}
 
Example 16
Source File: DynamoDbTemplateIntegrationTest.java    From Cheddar with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldUpdate_viaBatchWrite_withSingleItem() {
    // Given
    final DynamoDbTemplate dynamoDbTemplate = new DynamoDbTemplate(databaseSchemaHolder);
    dynamoDbTemplate.initialize(amazonDynamoDbClient);
    final StubItem createdItem = dataGenerator.createStubItem();
    final Long originalVersion = createdItem.getVersion();
    final String stringProperty = randomString(10);
    final String stringProperty2 = randomString(10);
    final Set<String> newStringSetProperty = Sets.newSet(randomString(10), randomString(10), randomString(10));
    createdItem.setStringProperty(stringProperty);
    createdItem.setStringProperty2(stringProperty2);
    createdItem.setStringSetProperty(newStringSetProperty);
    final Long newVersion = originalVersion + 1;

    final List<StubItem> stubItems = new ArrayList<>();
    stubItems.add(createdItem);

    // When
    final List<StubItem> successfulStubItems = dynamoDbTemplate.batchWrite(stubItems, StubItem.class);

    // Then
    for (final StubItem aStubItem : successfulStubItems) {
        assertEquals(newVersion, aStubItem.getVersion());
        assertEquals(createdItem.getId(), aStubItem.getId());
        assertEquals(stringProperty, aStubItem.getStringProperty());
        assertEquals(stringProperty2, aStubItem.getStringProperty2());
        assertEquals(newStringSetProperty, aStubItem.getStringSetProperty());
    }
}
 
Example 17
Source File: ConditionTest.java    From Cheddar with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldCreateCondition_withComparisonOperatorAndValueSet() throws Exception {
    // Given
    final Operators randomComparisonOperator = randomEnum(Operators.class);
    final Set<String> values = Sets.newSet(randomString(10), randomString(10), randomString(10));

    // When
    final Condition condition = new Condition(randomComparisonOperator, values);

    // Then
    assertNotNull(condition);
    assertEquals(randomComparisonOperator, condition.getComparisonOperator());
    assertEquals(values.size(), condition.getValues().size());
}
 
Example 18
Source File: SerializationTest.java    From pravega with Apache License 2.0 4 votes vote down vote up
@Test
public void containersetTest() throws IOException {
    ContainerSet set = new ContainerSet(Sets.newSet(1, 2, 3, 4));
    byte[] serialized = ContainerSet.SERIALIZER.serialize(set).getCopy();
    assertEquals(set.getContainerSet(), ContainerSet.SERIALIZER.deserialize(serialized).getContainerSet());
}
 
Example 19
Source File: StubFeatureService.java    From Cheddar with Apache License 2.0 4 votes vote down vote up
@Override
public Set<String> featureSetIds() {
    return Sets.newSet("FEATURE_SET_1", "FEATURE_SET_2", "FEATURE_SET_3");
}
 
Example 20
Source File: ItemHashUtilTest.java    From sakai with Educational Community License v2.0 4 votes vote down vote up
@Test
public void testHashItemGeneratesSha256OfHashBase() throws IOException, NoSuchAlgorithmException, ServerOverloadException {

    final ItemData item = new ItemData();
    item.setTypeId(TypeIfc.FILL_IN_BLANK);

    item.setInstruction(resourceDocTemplate1(fullUrlForContentResource(CONTENT_RESOURCES[0])));
    item.setCorrectItemFeedback(resourceDocTemplate1(fullUrlForContentResource(CONTENT_RESOURCES[1])));
    item.setInCorrectItemFeedback(resourceDocTemplate1(fullUrlForContentResource(CONTENT_RESOURCES[2])));
    item.setGeneralItemFeedback(resourceDocTemplate1(fullUrlForContentResource(CONTENT_RESOURCES[3])));
    item.setDescription(resourceDocTemplate1(fullUrlForContentResource(CONTENT_RESOURCES[4])));

    // just the "first two" metadata fields should be sufficient to prove metadata is being included
    final ItemMetaDataIfc metaData1 = newItemMetaData(item, ItemMetaDataIfc.RANDOMIZE, 11);
    final ItemMetaDataIfc metaData2 = newItemMetaData(item, ItemMetaDataIfc.REQUIRE_ALL_OK, 12);
    item.setItemMetaDataSet(Sets.newSet(metaData1,metaData2));

    final ItemAttachment attachment = new ItemAttachment(1L, item, idForContentResource(CONTENT_RESOURCES[5]), CONTENT_RESOURCES[5][CR_NAME_IDX], null, Long.MAX_VALUE - 1, null, null, null, null, null, null, null, null);
    item.setItemAttachmentSet(Sets.newSet(attachment));

    final Pair<Answer,String> answer = answerAndExpectedHashBaseFor(item, 1L, true, "Label 1", CONTENT_RESOURCES[6], CONTENT_RESOURCES[7], CONTENT_RESOURCES[8], CONTENT_RESOURCES[9]);
    final ItemText itemText = new ItemText(item, 1L, resourceDocTemplate1(fullUrlForContentResource(CONTENT_RESOURCES[10])), Sets.newSet(answerFrom(answer)));
    answerFrom(answer).setItemText(itemText);
    item.setItemTextSet(Sets.newSet(itemText));

    final ItemTag itemTag = new ItemTag(item, "tag1", "taglabel1", "tagcollection1", "tagcollectionname1");
    item.setItemTagSet(Sets.newSet(itemTag));

    expectServerUrlLookup();
    IntStream.rangeClosed(0, 12).forEach(
            i -> expectResourceLookupUnchecked(CONTENT_RESOURCES[i])
    );

    final StringBuilder expectedHashBase = new StringBuilder(labeled("TypeId","" + TypeIfc.FILL_IN_BLANK))
            .append(labeled("ItemText",renderBlanks(resourceDocTemplate1(expectedContentResourceHash1(CONTENT_RESOURCES[10])))))
            .append(labeled("Instruction",resourceDocTemplate1(expectedContentResourceHash1(CONTENT_RESOURCES[0]))))
            .append(labeled("CorrectItemFeedback",resourceDocTemplate1(expectedContentResourceHash1(CONTENT_RESOURCES[1]))))
            .append(labeled("IncorrectItemFeedback",resourceDocTemplate1(expectedContentResourceHash1(CONTENT_RESOURCES[2]))))
            .append(labeled("GeneralCorrectItemFeedback",resourceDocTemplate1(expectedContentResourceHash1(CONTENT_RESOURCES[3]))))
            .append(labeled("Description",resourceDocTemplate1(expectedContentResourceHash1(CONTENT_RESOURCES[4]))))
            .append(expectedContentResourceHash1(CONTENT_RESOURCES[5]))
            .append(stringFrom(answer))
            .append(labeled("RANDOMIZE",resourceDocTemplate1(fullUrlForContentResource(CONTENT_RESOURCES[11])))) // this specific MD field not actually treated as resource doc
            .append(labeled("REQUIRE_ALL_OK",resourceDocTemplate1(fullUrlForContentResource(CONTENT_RESOURCES[12])))); // this specific MD field not actually treated as resource doc

    // nulls for the other 14 "important" metadata keys
    //IntStream.rangeClosed(0, 13).forEach(
    //        i -> expectedHashBase.append("null")
    //);

    // convenient for debugging where the hash goes off the rails by looking at where the underlying "base" string goes off the rails...
    assertThat(itemHashUtil.hashBaseForItem(item).toString(), equalTo(expectedHashBase.toString()));

    final String expectedHash = sha256(bytes(expectedHashBase.toString()));
    final String actualHash1 = itemHashUtil.hashItem(item);
    final String actualHash2 = itemHashUtil.hashItem(item);
    assertThat(actualHash1, equalTo(expectedHash));
    assertThat("Hash is not stable", actualHash2, equalTo(expectedHash)); // believe it or not, this failed at one point (test bug w/r/t stream mgmt)
}