Example usage for java.util.stream IntStream rangeClosed

List of usage examples for java.util.stream IntStream rangeClosed

Introduction

In this page you can find the example usage for java.util.stream IntStream rangeClosed.

Prototype

public static IntStream rangeClosed(int startInclusive, int endInclusive) 

Source Link

Document

Returns a sequential ordered IntStream from startInclusive (inclusive) to endInclusive (inclusive) by an incremental step of 1 .

Usage

From source file:org.protelis.test.TestLanguage.java

private static void testFileWithMultipleRuns(final String file, final int min, final int max) {
    testFileWithMultipleRuns(file, IntStream.rangeClosed(min, max));
}

From source file:org.sakaiproject.tool.assessment.facade.ItemHashUtilTest.java

@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);//from   w ww.  j ava  2  s.  c o  m
    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)
}

From source file:org.sakaiproject.tool.assessment.facade.ItemHashUtilTest.java

/**
 * Same as {@link #testHashItemGeneratesSha256OfHashBase()} but verifies that a slightly different hash base is
 * used if the item type is {@link TypeIfc#EXTENDED_MATCHING_ITEMS}
 *///  ww  w . j  ava  2s  .c o m
@Test
public void testHashItemGeneratesSha256OfHashBaseForExtendedMatchingItem()
        throws IOException, NoSuchAlgorithmException, ServerOverloadException {
    final ItemData item = newExtendedMatchingItem();

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

    ArrayList<String[]> contentResourceDefs1 = new ArrayList<>();
    contentResourceDefs1.add(CONTENT_RESOURCES[18]);
    contentResourceDefs1.add(CONTENT_RESOURCES[8]);

    ArrayList<String[]> contentResourceDefs2 = new ArrayList<>();
    contentResourceDefs2.add(CONTENT_RESOURCES[14]); // hash of first ItemTextAttachment contents in first "combination" ItemText
    contentResourceDefs2.add(CONTENT_RESOURCES[13]); // hash of second ItemTextAttachent contents in first "combination" ItemText

    ArrayList<String[]> contentResourceDefs3 = new ArrayList<>();
    contentResourceDefs3.add(CONTENT_RESOURCES[16]); // hash of first ItemTextAttachment contents in second "combination" ItemText
    contentResourceDefs3.add(CONTENT_RESOURCES[17]); // hash of second ItemTextAttachent contents in second "combination" ItemText

    final StringBuilder expectedHashBase = new StringBuilder(
            labeled("TypeId", "" + TypeIfc.EXTENDED_MATCHING_ITEMS))
                    .append(labeled("ThemeText",
                            resourceDocTemplate1(expectedContentResourceHash1(CONTENT_RESOURCES[0])))) // themeText
                    .append(labeled("LeadInText",
                            resourceDocTemplate1(expectedContentResourceHash1(CONTENT_RESOURCES[1])))) // leadInText
                    .append(labeled("CorrectItemFeedback",
                            resourceDocTemplate1(expectedContentResourceHash1(CONTENT_RESOURCES[2])))) // correct feedback
                    .append(labeled("IncorrectItemFeedback",
                            resourceDocTemplate1(expectedContentResourceHash1(CONTENT_RESOURCES[3])))) // incorrect feedback
                    .append(labeled("GeneralCorrectItemFeedback",
                            resourceDocTemplate1(expectedContentResourceHash1(CONTENT_RESOURCES[4])))) // general feedback
                    .append(labeled("Description",
                            resourceDocTemplate1(expectedContentResourceHash1(CONTENT_RESOURCES[5])))) // description
                    // 18 then 8 for same reason 13 and 14 are reversed below
                    .append(expectedContentResourceHashAttachments(contentResourceDefs1)) // first and second attachment
                    .append(labeled("EmiLabel",
                            resourceDocTemplate1(expectedContentResourceHash1(CONTENT_RESOURCES[9])))) // first 'options' answer label
                    .append(labeled("EmiLabel",
                            resourceDocTemplate1(expectedContentResourceHash1(CONTENT_RESOURCES[10])))) // second 'options' answer label
                    .append(labeled("EmiCorrectOptionLabels", "Answer Label 3Answer Label 5")) //correct Answer labels for first "combination" ItemText
                    .append(labeled("EmiSequence", "" + Long.MAX_VALUE)) // sequence value for first "combination" ItemText
                    .append(labeled("EmiText",
                            resourceDocTemplate1(expectedContentResourceHash1(CONTENT_RESOURCES[12])))) // text for first "combination" ItemText
                    // 14 then 13 b/c itemattachments and itemtextattachments are sorted into the hash base by *their*
                    // hashes, rather than by, say, resourceId. as noted in ItemFacadeQueries.hashBaseForResourceIds() this
                    // a bit unfortunate but is really our only means to ensure a consistent sort order for attachments (at
                    // least assuming the hashing implementation itself remains fixed, which it has to be for the overall
                    // item hashing to be stable).
                    .append(expectedContentResourceHashAttachments(contentResourceDefs2))
                    .append(labeled("EmiCorrectOptionLabels", "Answer Label 6Answer Label 8")) //correct Answer labels for second "combination" ItemText
                    .append(labeled("EmiSequence", "" + Long.MAX_VALUE)) // sequence value for second "combination" ItemText
                    .append(labeled("EmiText",
                            resourceDocTemplate1(expectedContentResourceHash1(CONTENT_RESOURCES[15])))) // text for second "combination" ItemText
                    .append(expectedContentResourceHashAttachments(contentResourceDefs3))
                    .append(labeled("RANDOMIZE",
                            resourceDocTemplate1(fullUrlForContentResource(CONTENT_RESOURCES[6])))) // this specific MD field not actually treated as resource doc
                    .append(labeled("REQUIRE_ALL_OK",
                            resourceDocTemplate1(fullUrlForContentResource(CONTENT_RESOURCES[7])))); // 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")
    //);

    final String expectedHash = sha256(bytes(expectedHashBase.toString()));

    // 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 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)

}

From source file:org.sakaiproject.tool.assessment.facade.ItemHashUtilTest.java

@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();/*from  w w w .jav a  2  s  . c  o m*/
    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()));
}

From source file:org.sakaiproject.tool.assessment.facade.ItemHashUtilTest.java

@Test
public void testHashBaseForItemAnswersIncludesSimpleAnswerOptionsForExtendedMatchingItems()
        throws IOException, NoSuchAlgorithmException, ServerOverloadException {
    final ItemData item = newExtendedMatchingItem();

    expectServerUrlLookup();/*from  w  w  w . j a v a2  s .  co m*/
    IntStream.rangeClosed(0, 18).forEach(i -> expectResourceLookupUnchecked(CONTENT_RESOURCES[i]));

    ArrayList<String[]> contentResourceDefs1 = new ArrayList<>();
    contentResourceDefs1.add(CONTENT_RESOURCES[14]); // hash of first ItemTextAttachment contents in first "combination" ItemText
    contentResourceDefs1.add(CONTENT_RESOURCES[13]); // hash of second ItemTextAttachent contents in first "combination" ItemText

    ArrayList<String[]> contentResourceDefs2 = new ArrayList<>();
    contentResourceDefs2.add(CONTENT_RESOURCES[16]); // hash of first ItemTextAttachent contents in second "combination" ItemText
    contentResourceDefs2.add(CONTENT_RESOURCES[17]); // hash of second ItemTextAttachent contents in second "combination" ItemText

    final StringBuilder expectedHashBase = new StringBuilder()
            .append(labeled("EmiLabel",
                    resourceDocTemplate1(expectedContentResourceHash1(CONTENT_RESOURCES[9])))) // first 'options' Answer label
            .append(labeled("EmiLabel",
                    resourceDocTemplate1(expectedContentResourceHash1(CONTENT_RESOURCES[10])))) // second 'options' Answer label
            .append(labeled("EmiCorrectOptionLabels", "Answer Label 3Answer Label 5")) //correct Answer labels for first "combination" ItemText
            .append(labeled("EmiSequence", "" + Long.MAX_VALUE)) // sequence value for first "combination" ItemText
            .append(labeled("EmiText",
                    resourceDocTemplate1(expectedContentResourceHash1(CONTENT_RESOURCES[12])))) // text for first "combination" ItemText
            // 14 then 13 b/c itemattachments and itemtextattachments are sorted into the hash base by *their*
            // hashes, rather than by, say, resourceId. as noted in ItemFacadeQueries.hashBaseForResourceIds() this
            // a bit unfortunate but is really our only means to ensure a consistent sort order for attachments (at
            // least assuming the hashing implementation itself remains fixed, which it has to be for the overall
            // item hashing to be stable).
            .append(expectedContentResourceHashAttachments(contentResourceDefs1))
            .append(labeled("EmiCorrectOptionLabels", "Answer Label 6Answer Label 8")) //correct Answer labels for second "combination" ItemText
            .append(labeled("EmiSequence", "" + Long.MAX_VALUE)) // sequence value for second "combination" ItemText
            .append(labeled("EmiText",
                    resourceDocTemplate1(expectedContentResourceHash1(CONTENT_RESOURCES[15])))) // text for second "combination" ItemText
            .append(expectedContentResourceHashAttachments(contentResourceDefs2));

    StringBuilder actualHashBase = new StringBuilder();
    itemHashUtil.hashBaseForItemAnswers(item, actualHashBase);
    assertThat(actualHashBase.toString(), equalTo(expectedHashBase.toString()));
}

From source file:org.sakaiproject.tool.assessment.facade.ItemHashUtilTest.java

@Test
public void testHashBaseForItemAnswersIncludesAnswerOptionsRichTextInsteadOfAnswerOptionLabelsForExtendedMatchingItems()
        throws IOException, NoSuchAlgorithmException, ServerOverloadException {
    final ItemData item = newExtendedMatchingItem();

    // the key distinguisher between this test and
    // testHashBaseForItemAnswersIncludesSimpleAnswerOptionsForExtendedMatchingItems()
    item.setAnswerOptionsSimpleOrRich(ItemDataIfc.ANSWER_OPTIONS_RICH);

    expectServerUrlLookup();//from ww  w  .j a  va  2  s.  c o  m
    IntStream.rangeClosed(0, 18).forEach(i -> expectResourceLookupUnchecked(CONTENT_RESOURCES[i]));

    ArrayList<String[]> contentResourceDefs1 = new ArrayList<>();
    contentResourceDefs1.add(CONTENT_RESOURCES[14]); // hash of first ItemTextAttachment contents in first "combination" ItemText
    contentResourceDefs1.add(CONTENT_RESOURCES[13]); // hash of second ItemTextAttachent contents in first "combination" ItemText

    ArrayList<String[]> contentResourceDefs2 = new ArrayList<>();
    contentResourceDefs2.add(CONTENT_RESOURCES[16]); // hash of first ItemTextAttachent contents in second "combination" ItemText
    contentResourceDefs2.add(CONTENT_RESOURCES[17]); // hash of second ItemTextAttachent contents in second "combination" ItemText

    final StringBuilder expectedHashBase = new StringBuilder()
            .append(labeled("EmiAnswerOptionsRichText",
                    resourceDocTemplate1(expectedContentResourceHash1(CONTENT_RESOURCES[11])))) // rich text
            .append(labeled("EmiCorrectOptionLabels", "Answer Label 3Answer Label 5")) //correct Answer labels for first "combination" ItemText
            .append(labeled("EmiSequence", "" + Long.MAX_VALUE)) // sequence value for first "combination" ItemText
            .append(labeled("EmiText",
                    resourceDocTemplate1(expectedContentResourceHash1(CONTENT_RESOURCES[12])))) // text for first "combination" ItemText
            // 14 then 13 b/c itemattachments and itemtextattachments are sorted into the hash base by *their*
            // hashes, rather than by, say, resourceId. as noted in ItemFacadeQueries.hashBaseForResourceIds() this
            // a bit unfortunate but is really our only means to ensure a consistent sort order for attachments (at
            // least assuming the hashing implementation itself remains fixed, which it has to be for the overall
            // item hashing to be stable).
            .append(expectedContentResourceHashAttachments(contentResourceDefs1))
            .append(labeled("EmiCorrectOptionLabels", "Answer Label 6Answer Label 8")) //correct Answer labels for second "combination" ItemText
            .append(labeled("EmiSequence", "" + Long.MAX_VALUE)) // sequence value for second "combination" ItemText
            .append(labeled("EmiText",
                    resourceDocTemplate1(expectedContentResourceHash1(CONTENT_RESOURCES[15])))) // text for second "combination" ItemText
            .append(expectedContentResourceHashAttachments(contentResourceDefs2));

    StringBuilder actualHashBase = new StringBuilder();
    itemHashUtil.hashBaseForItemAnswers(item, actualHashBase);
    assertThat(actualHashBase.toString(), equalTo(expectedHashBase.toString()));
}

From source file:org.sakaiproject.tool.assessment.facade.ItemHashUtilTest.java

@Test
public void testHashBaseForItemMetadata()
        throws IOException, NoSuchAlgorithmException, ServerOverloadException {
    // use a html doc for each (except for IMAGE_MAP_SRC which is an extra special case), even tho code only
    // assumes a small subset are actually html docs. easy way of verifying whether or not individual properties
    // are or are not routed through resource hashing routines.

    final ItemData item = new ItemData();
    item.setTypeId(TypeIfc.FILL_IN_BLANK);
    final ItemMetaDataIfc metaData1 = newItemMetaData(item, ItemMetaDataIfc.RANDOMIZE, 0);
    final ItemMetaDataIfc metaData2 = newItemMetaData(item, ItemMetaDataIfc.REQUIRE_ALL_OK, 1);
    final ItemMetaDataIfc metaData3 = new ItemMetaData(item, ItemMetaDataIfc.IMAGE_MAP_SRC,
            serverRelativeUrlForContentResource(CONTENT_RESOURCES[2]));
    final ItemMetaDataIfc metaData4 = newItemMetaData(item, ItemMetaDataIfc.CASE_SENSITIVE_FOR_FIB, 3);
    final ItemMetaDataIfc metaData5 = newItemMetaData(item, ItemMetaDataIfc.MUTUALLY_EXCLUSIVE_FOR_FIB, 4);
    final ItemMetaDataIfc metaData6 = newItemMetaData(item, ItemMetaDataIfc.IGNORE_SPACES_FOR_FIB, 5);
    final ItemMetaDataIfc metaData7 = newItemMetaData(item, ItemMetaDataIfc.MCMS_PARTIAL_CREDIT, 6);
    final ItemMetaDataIfc metaData8 = newItemMetaData(item, ItemMetaDataIfc.FORCE_RANKING, 7);
    final ItemMetaDataIfc metaData9 = newItemMetaData(item, ItemMetaDataIfc.MX_SURVEY_RELATIVE_WIDTH, 8);
    final ItemMetaDataIfc metaData10 = newItemMetaData(item, ItemMetaDataIfc.ADD_COMMENT_MATRIX, 9);
    final ItemMetaDataIfc metaData11 = newItemMetaData(item, ItemMetaDataIfc.MX_SURVEY_QUESTION_COMMENTFIELD,
            10);// w  ww .j av  a 2  s  .  co m
    final ItemMetaDataIfc metaData12 = newItemMetaData(item, ItemMetaDataIfc.PREDEFINED_SCALE, 11);
    final ItemMetaDataIfc metaData13 = newItemMetaData(item, ItemMetaDataIfc.TIMEALLOWED, 12);
    final ItemMetaDataIfc metaData14 = newItemMetaData(item, ItemMetaDataIfc.NUMATTEMPTS, 13);
    final ItemMetaDataIfc metaData15 = newItemMetaData(item, ItemMetaDataIfc.SCALENAME, 14);
    final ItemMetaDataIfc metaData16 = newItemMetaData(item, ItemMetaDataIfc.ADD_TO_FAVORITES_MATRIX, 15);
    final ItemMetaDataIfc metaData17 = newItemMetaData(item, ItemMetaDataIfc.IMAGE_MAP_ALT_TEXT, 16);
    item.setItemMetaDataSet(Sets.newSet(metaData1, metaData2, metaData3, metaData4, metaData5, metaData6,
            metaData7, metaData8, metaData9, metaData10, metaData11, metaData12, metaData12, metaData13,
            metaData14, metaData15, metaData16, metaData17));

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

    final StringBuilder expectedHashBase = new StringBuilder()
            .append(labeled(ItemMetaDataIfc.RANDOMIZE,
                    resourceDocTemplate1(fullUrlForContentResource(CONTENT_RESOURCES[0]))))
            .append(labeled(ItemMetaDataIfc.REQUIRE_ALL_OK,
                    resourceDocTemplate1(fullUrlForContentResource(CONTENT_RESOURCES[1]))))
            .append(labeled(ItemMetaDataIfc.IMAGE_MAP_SRC, expectedContentResourceHash1(CONTENT_RESOURCES[2])))
            .append(labeled(ItemMetaDataIfc.CASE_SENSITIVE_FOR_FIB,
                    resourceDocTemplate1(fullUrlForContentResource(CONTENT_RESOURCES[3]))))
            .append(labeled(ItemMetaDataIfc.MUTUALLY_EXCLUSIVE_FOR_FIB,
                    resourceDocTemplate1(fullUrlForContentResource(CONTENT_RESOURCES[4]))))
            .append(labeled(ItemMetaDataIfc.IGNORE_SPACES_FOR_FIB,
                    resourceDocTemplate1(fullUrlForContentResource(CONTENT_RESOURCES[5]))))
            .append(labeled(ItemMetaDataIfc.MCMS_PARTIAL_CREDIT,
                    resourceDocTemplate1(fullUrlForContentResource(CONTENT_RESOURCES[6]))))
            .append(labeled(ItemMetaDataIfc.FORCE_RANKING,
                    resourceDocTemplate1(fullUrlForContentResource(CONTENT_RESOURCES[7]))))
            .append(labeled(ItemMetaDataIfc.MX_SURVEY_RELATIVE_WIDTH,
                    resourceDocTemplate1(fullUrlForContentResource(CONTENT_RESOURCES[8]))))
            .append(labeled(ItemMetaDataIfc.ADD_COMMENT_MATRIX,
                    resourceDocTemplate1(fullUrlForContentResource(CONTENT_RESOURCES[9]))))
            .append(labeled(ItemMetaDataIfc.MX_SURVEY_QUESTION_COMMENTFIELD,
                    resourceDocTemplate1(expectedContentResourceHash1(CONTENT_RESOURCES[10]))))
            .append(labeled(ItemMetaDataIfc.PREDEFINED_SCALE,
                    resourceDocTemplate1(fullUrlForContentResource(CONTENT_RESOURCES[11]))))
            .append(labeled(ItemMetaDataIfc.TIMEALLOWED,
                    resourceDocTemplate1(fullUrlForContentResource(CONTENT_RESOURCES[12]))))
            .append(labeled(ItemMetaDataIfc.NUMATTEMPTS,
                    resourceDocTemplate1(fullUrlForContentResource(CONTENT_RESOURCES[13]))))
            .append(labeled(ItemMetaDataIfc.SCALENAME,
                    resourceDocTemplate1(fullUrlForContentResource(CONTENT_RESOURCES[14]))))
            .append(labeled(ItemMetaDataIfc.ADD_TO_FAVORITES_MATRIX,
                    resourceDocTemplate1(fullUrlForContentResource(CONTENT_RESOURCES[15]))))
            .append(labeled(ItemMetaDataIfc.IMAGE_MAP_ALT_TEXT,
                    resourceDocTemplate1(fullUrlForContentResource(CONTENT_RESOURCES[16]))));

    final StringBuilder actualHashBase = new StringBuilder();
    itemHashUtil.hashBaseForItemMetadata(item, actualHashBase);
    assertThat(actualHashBase.toString(), equalTo(expectedHashBase.toString()));

}

From source file:org.sakaiproject.tool.assessment.facade.ItemHashUtilTest.java

@Test
public void testHashBaseForItemMetadataSkipsMissingResources()
        throws NoSuchAlgorithmException, IOException, ServerOverloadException {
    final ItemData item = new ItemData();
    item.setTypeId(TypeIfc.FILL_IN_BLANK);
    final ItemMetaDataIfc metaData1 = newItemMetaData(item, ItemMetaDataIfc.RANDOMIZE, 0);
    final ItemMetaDataIfc metaData2 = newItemMetaData(item, ItemMetaDataIfc.REQUIRE_ALL_OK, 1);
    final ItemMetaDataIfc metaData3 = new ItemMetaData(item, ItemMetaDataIfc.IMAGE_MAP_SRC,
            serverRelativeUrlForContentResource(CONTENT_RESOURCES[2]));
    final ItemMetaDataIfc metaData4 = newItemMetaData(item, ItemMetaDataIfc.CASE_SENSITIVE_FOR_FIB, 3);
    final ItemMetaDataIfc metaData5 = newItemMetaData(item, ItemMetaDataIfc.MUTUALLY_EXCLUSIVE_FOR_FIB, 4);
    final ItemMetaDataIfc metaData6 = newItemMetaData(item, ItemMetaDataIfc.IGNORE_SPACES_FOR_FIB, 5);
    final ItemMetaDataIfc metaData7 = newItemMetaData(item, ItemMetaDataIfc.MCMS_PARTIAL_CREDIT, 6);
    final ItemMetaDataIfc metaData8 = newItemMetaData(item, ItemMetaDataIfc.FORCE_RANKING, 7);
    final ItemMetaDataIfc metaData9 = newItemMetaData(item, ItemMetaDataIfc.MX_SURVEY_RELATIVE_WIDTH, 8);
    final ItemMetaDataIfc metaData10 = newItemMetaData(item, ItemMetaDataIfc.ADD_COMMENT_MATRIX, 9);
    final ItemMetaDataIfc metaData11 = newItemMetaData(item, ItemMetaDataIfc.MX_SURVEY_QUESTION_COMMENTFIELD,
            10);//  www . ja  v a2 s . c  om
    final ItemMetaDataIfc metaData12 = newItemMetaData(item, ItemMetaDataIfc.PREDEFINED_SCALE, 11);
    final ItemMetaDataIfc metaData13 = newItemMetaData(item, ItemMetaDataIfc.TIMEALLOWED, 12);
    final ItemMetaDataIfc metaData14 = newItemMetaData(item, ItemMetaDataIfc.NUMATTEMPTS, 13);
    final ItemMetaDataIfc metaData15 = newItemMetaData(item, ItemMetaDataIfc.SCALENAME, 14);
    final ItemMetaDataIfc metaData16 = newItemMetaData(item, ItemMetaDataIfc.ADD_TO_FAVORITES_MATRIX, 15);
    item.setItemMetaDataSet(Sets.newSet(metaData1, metaData2, metaData3, metaData4, metaData5, metaData6,
            metaData7, metaData8, metaData9, metaData10, metaData11, metaData12, metaData12, metaData13,
            metaData14, metaData15, metaData16));

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

    final StringBuilder expectedHashBase = new StringBuilder()
            .append(labeled(ItemMetaDataIfc.RANDOMIZE,
                    resourceDocTemplate1(fullUrlForContentResource(CONTENT_RESOURCES[0]))))
            .append(labeled(ItemMetaDataIfc.REQUIRE_ALL_OK,
                    resourceDocTemplate1(fullUrlForContentResource(CONTENT_RESOURCES[1]))))
            .append(labeled(ItemMetaDataIfc.IMAGE_MAP_SRC,
                    serverRelativeUrlForContentResource(CONTENT_RESOURCES[2])))
            .append(labeled(ItemMetaDataIfc.CASE_SENSITIVE_FOR_FIB,
                    resourceDocTemplate1(fullUrlForContentResource(CONTENT_RESOURCES[3]))))
            .append(labeled(ItemMetaDataIfc.MUTUALLY_EXCLUSIVE_FOR_FIB,
                    resourceDocTemplate1(fullUrlForContentResource(CONTENT_RESOURCES[4]))))
            .append(labeled(ItemMetaDataIfc.IGNORE_SPACES_FOR_FIB,
                    resourceDocTemplate1(fullUrlForContentResource(CONTENT_RESOURCES[5]))))
            .append(labeled(ItemMetaDataIfc.MCMS_PARTIAL_CREDIT,
                    resourceDocTemplate1(fullUrlForContentResource(CONTENT_RESOURCES[6]))))
            .append(labeled(ItemMetaDataIfc.FORCE_RANKING,
                    resourceDocTemplate1(fullUrlForContentResource(CONTENT_RESOURCES[7]))))
            .append(labeled(ItemMetaDataIfc.MX_SURVEY_RELATIVE_WIDTH,
                    resourceDocTemplate1(fullUrlForContentResource(CONTENT_RESOURCES[8]))))
            .append(labeled(ItemMetaDataIfc.ADD_COMMENT_MATRIX,
                    resourceDocTemplate1(fullUrlForContentResource(CONTENT_RESOURCES[9]))))
            .append(labeled(ItemMetaDataIfc.MX_SURVEY_QUESTION_COMMENTFIELD,
                    resourceDocTemplate1(fullUrlForContentResource(CONTENT_RESOURCES[10]))))
            .append(labeled(ItemMetaDataIfc.PREDEFINED_SCALE,
                    resourceDocTemplate1(fullUrlForContentResource(CONTENT_RESOURCES[11]))))
            .append(labeled(ItemMetaDataIfc.TIMEALLOWED,
                    resourceDocTemplate1(fullUrlForContentResource(CONTENT_RESOURCES[12]))))
            .append(labeled(ItemMetaDataIfc.NUMATTEMPTS,
                    resourceDocTemplate1(fullUrlForContentResource(CONTENT_RESOURCES[13]))))
            .append(labeled(ItemMetaDataIfc.SCALENAME,
                    resourceDocTemplate1(fullUrlForContentResource(CONTENT_RESOURCES[14]))))
            .append(labeled(ItemMetaDataIfc.ADD_TO_FAVORITES_MATRIX,
                    resourceDocTemplate1(fullUrlForContentResource(CONTENT_RESOURCES[15]))));

    final StringBuilder actualHashBase = new StringBuilder();
    itemHashUtil.hashBaseForItemMetadata(item, actualHashBase);
    assertThat(actualHashBase.toString(), equalTo(expectedHashBase.toString()));
}

From source file:org.sakaiproject.tool.assessment.facade.ItemHashUtilTest.java

@Test
public void testHashBaseForItemMetadataSkipsUnimportantKeys()
        throws NoSuchAlgorithmException, IOException, ServerOverloadException {
    final ItemData item = new ItemData();
    item.setTypeId(TypeIfc.FILL_IN_BLANK);
    final ItemMetaDataIfc metaData1 = newItemMetaData(item, ItemMetaDataIfc.RANDOMIZE, 0);
    final ItemMetaDataIfc metaData2 = newItemMetaData(item, ItemMetaDataIfc.OBJECTIVE, 1); // this one should be ignored
    final ItemMetaDataIfc metaData3 = newItemMetaData(item, ItemMetaDataIfc.REQUIRE_ALL_OK, 2);
    item.setItemMetaDataSet(Sets.newSet(metaData1, metaData2, metaData3));

    final StringBuilder expectedHashBase = new StringBuilder()
            .append("RANDOMIZE:" + resourceDocTemplate1(fullUrlForContentResource(CONTENT_RESOURCES[0])) + "::")
            .append("REQUIRE_ALL_OK:" + resourceDocTemplate1(fullUrlForContentResource(CONTENT_RESOURCES[2]))
                    + "::");

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

    final StringBuilder actualHashBase = new StringBuilder();
    itemHashUtil.hashBaseForItemMetadata(item, actualHashBase);
    assertThat(actualHashBase.toString(), equalTo(expectedHashBase.toString()));
}

From source file:org.sonar.server.qualityprofile.RuleActivatorTest.java

@Test
public void bulk_activation() {
    int bulkSize = SearchOptions.MAX_LIMIT + 10 + new Random().nextInt(100);
    String language = randomAlphanumeric(10);
    String repositoryKey = randomAlphanumeric(10);
    QProfileDto profile = db.qualityProfiles().insert(db.getDefaultOrganization(),
            p -> p.setLanguage(language));

    List<RuleDto> rules = new ArrayList<>();
    IntStream.rangeClosed(1, bulkSize).forEach(i -> rules
            .add(db.rules().insertRule(r -> r.setLanguage(language).setRepositoryKey(repositoryKey))));

    verifyNoActiveRules();/*from w  w  w . j  ava 2  s . c o m*/
    ruleIndexer.indexOnStartup(ruleIndexer.getIndexTypes());

    RuleQuery ruleQuery = new RuleQuery().setRepositories(singletonList(repositoryKey));

    BulkChangeResult bulkChangeResult = underTest.bulkActivateAndCommit(db.getSession(), ruleQuery, profile,
            MINOR);

    assertThat(bulkChangeResult.countFailed()).isEqualTo(0);
    assertThat(bulkChangeResult.countSucceeded()).isEqualTo(bulkSize);
    assertThat(bulkChangeResult.getChanges()).hasSize(bulkSize);
    assertThat(db.getDbClient().activeRuleDao().selectByProfile(db.getSession(), profile)).hasSize(bulkSize);
    rules.stream()
            .forEach(r -> assertThatRuleIsActivated(profile, r.getDefinition(), null, MINOR, null, emptyMap()));
}