selectedVariantMock1.expects.getVariant().returns(variantMock).any();
selectedVariantMock1.expects.getPolicy().returns(policyMock1).any();
selectedVariantMock1.expects.getOldObject().returns(
new ScriptAsset("name1", "deviceName1", "javascript1", "mimeType1",
"charSet1", ScriptAsset.URL, "assetGroupName1", "value1")).any();
final DefaultComponentScriptAssetReference scriptAssetReference1 =
new DefaultComponentScriptAssetReference(
runtimePolicyReferenceMock1, assetResolverMock);
assertTrue(slm.addScript(scriptAssetReference1));
final ActivatedVariablePolicyMock policyMock2 =
new ActivatedVariablePolicyMock("ActivatedVariablePolicyMock2",
expectations);
policyMock2.expects.getName().returns("name2").any();
final SelectedVariantMock selectedVariantMock2 =
new SelectedVariantMock("SelectedVariantMock2", expectations);
selectedVariantMock2.expects.getVariant().returns(variantMock).any();
selectedVariantMock2.expects.getPolicy().returns(policyMock2).any();
selectedVariantMock2.expects.getOldObject().returns(
new ScriptAsset("name2", "deviceName2", "javascript2", "mimeType2",
"charSet2", ScriptAsset.URL, "assetGroupName2", "value2")).any();
assetResolverMock.expects.selectBestVariant(
runtimePolicyReferenceMock2, null).returns(selectedVariantMock2).any();
final DefaultComponentScriptAssetReference scriptAssetReference2 =
new DefaultComponentScriptAssetReference(
runtimePolicyReferenceMock2, assetResolverMock);
assertTrue(slm.addScript(scriptAssetReference2));
final SelectedVariantMock selectedVariantMock1b =
new SelectedVariantMock("SelectedVariantMock1b", expectations);
selectedVariantMock1b.expects.getVariant().returns(variantMock).any();
selectedVariantMock1b.expects.getPolicy().returns(policyMock1).any();
selectedVariantMock1b.expects.getOldObject().returns(new ScriptAsset(
"name1b", "deviceName1b", "javascript1b", "mimeType1b", "charSet1b",
ScriptAsset.URL, "assetGroupName1b", "value1b")).any();
final DefaultComponentScriptAssetReference scriptAssetReference1b =
new DefaultComponentScriptAssetReference(
runtimePolicyReferenceMock1, assetResolverMock);
assertFalse(slm.addScript(scriptAssetReference1b));
final ActivatedVariablePolicyMock policyMock3 =
new ActivatedVariablePolicyMock("ActivatedVariablePolicyMock3",
expectations);
policyMock3.expects.getName().returns("name3").any();
final SelectedVariantMock selectedVariantMock3 =
new SelectedVariantMock("SelectedVariantMock3", expectations);
selectedVariantMock3.expects.getVariant().returns(variantMock).any();
selectedVariantMock3.expects.getPolicy().returns(policyMock3).any();
selectedVariantMock3.expects.getOldObject().returns(
new ScriptAsset("name3", "deviceName3", "javascript3", "mimeType3",
"charSet3", ScriptAsset.URL, "assetGroupName3", "value3")).any();
assetResolverMock.expects.selectBestVariant(
runtimePolicyReferenceMock3, null).returns(selectedVariantMock3).any();
final DefaultComponentScriptAssetReference scriptAssetReference3 =
new DefaultComponentScriptAssetReference(
runtimePolicyReferenceMock3, assetResolverMock);
assertTrue(slm.addScript(scriptAssetReference3));
assetResolverMock.expects.computeURLAsString(selectedVariantMock1).
returns("source1").any();
assetResolverMock.expects.computeURLAsString(selectedVariantMock2).
returns("source2").any();
assetResolverMock.expects.computeURLAsString(selectedVariantMock3).
returns("source3").any();
assetResolverMock.expects.rewriteURLWithPageURLRewriter("source1", PageURLType.SCRIPT)
.returns("source1").any();
assetResolverMock.expects.rewriteURLWithPageURLRewriter("source2", PageURLType.SCRIPT)
.returns("source2").any();
assetResolverMock.expects.rewriteURLWithPageURLRewriter("source3", PageURLType.SCRIPT)
.returns("source3").any();
slm.writeScriptElements();
assertEquals(3, scriptAttributesList.size());
final ScriptAttributes scriptAttributes1 =
(ScriptAttributes) scriptAttributesList.get(0);
assertEquals("charSet1", scriptAttributes1.getCharSet());
assertEquals("javascript1", scriptAttributes1.getLanguage());
assertEquals("source1", scriptAttributes1.getScriptReference().getURL());
final ScriptAttributes scriptAttributes2 =
(ScriptAttributes) scriptAttributesList.get(1);
assertEquals("charSet2", scriptAttributes2.getCharSet());
assertEquals("javascript2", scriptAttributes2.getLanguage());
assertEquals("source2", scriptAttributes2.getScriptReference().getURL());
final ScriptAttributes scriptAttributes3 =
(ScriptAttributes) scriptAttributesList.get(2);
assertEquals("charSet3", scriptAttributes3.getCharSet());
assertEquals("javascript3", scriptAttributes3.getLanguage());
assertEquals("source3", scriptAttributes3.getScriptReference().getURL());
final Element headRoot =
((DOMOutputBuffer) pageHead.getHead()).getRoot();
assertEquals("DELETE_ME", ((Element) headRoot.getHead()).getName());
final ActivatedVariablePolicyMock policyMock4 =
new ActivatedVariablePolicyMock("ActivatedVariablePolicyMock4",
expectations);
policyMock4.expects.getName().returns("name4").any();
final SelectedVariantMock selectedVariantMock4 =
new SelectedVariantMock("SelectedVariantMock4", expectations);
selectedVariantMock4.expects.getVariant().returns(variantMock).any();
selectedVariantMock4.expects.getPolicy().returns(policyMock4).any();
selectedVariantMock4.expects.getOldObject().returns(
new ScriptAsset("name4", "deviceName4", "javascript4", "mimeType4",
"charSet4", ScriptAsset.URL, "assetGroupName4", "value4")).any();
assetResolverMock.expects.selectBestVariant(
runtimePolicyReferenceMock4, null).returns(selectedVariantMock4).any();
assetResolverMock.expects.computeURLAsString(selectedVariantMock4).
returns("source4").any();
assetResolverMock.expects.rewriteURLWithPageURLRewriter("source4", PageURLType.SCRIPT).
returns("source4").any();
final DefaultComponentScriptAssetReference scriptAssetReference4 =
new DefaultComponentScriptAssetReference(
runtimePolicyReferenceMock4, assetResolverMock);
assertTrue(slm.addScript(scriptAssetReference4));
Element scriptElement = ((Element) headRoot.getHead());
assertEquals("script", scriptElement.getName());
assertEquals("charSet4", scriptElement.getAttributeValue("charset"));