DefaultValuesPolicyMuleArtifactJsonGenerator extends AbstractDefaultValuesMuleArtifactJsonGenerator { @Override protected void setBuilderWithDefaultBundleDescriptorLoaderValue(MuleApplicationModel.MuleApplicationModelBuilder builder, MuleApplicationModel originalMuleArtifact, MuleArtifactContentResolver artifactContentResolver) { MuleArtifactLoaderDescriptor bundleDescriptorLoader = originalMuleArtifact.getBundleDescriptorLoader(); Map<String, Object> attributes = bundleDescriptorLoader != null && originalMuleArtifact.getBundleDescriptorLoader().getAttributes() != null ? new HashMap<>(originalMuleArtifact.getBundleDescriptorLoader().getAttributes()) : new HashMap<>(); attributes.putIfAbsent(GROUP_ID, artifactContentResolver.getPom().getGroupId()); attributes.putIfAbsent(ARTIFACT_ID, artifactContentResolver.getPom().getArtifactId()); attributes.putIfAbsent(VERSION, artifactContentResolver.getPom().getVersion()); attributes.putIfAbsent(CLASSIFIER, MULE_POLICY.toString().toLowerCase()); attributes.putIfAbsent(TYPE, JAR_TYPE); builder.withBundleDescriptorLoader(new MuleArtifactLoaderDescriptor(MULE_ID, attributes)); }    }
@Test public void setBuilderWithDefaultBundleDescriptorLoaderNullValueTest() { MuleApplicationModel muleArtifactSpy = spy(muleArtifact); doReturn(null).when(muleArtifactSpy).getBundleDescriptorLoader(); MuleApplicationModel.MuleApplicationModelBuilder builder = new MuleApplicationModel.MuleApplicationModelBuilder(); Pom pomMock = mockPom(); MuleArtifactContentResolver resolverMock = mock(MuleArtifactContentResolver.class); when(resolverMock.getPom()).thenReturn(pomMock); generator.setBuilderWithDefaultBundleDescriptorLoaderValue(builder, muleArtifact, resolverMock); assertThat("Bundle descriptor loader id defined in builder is not the expected", builder.getBundleDescriptorLoader().getId(), equalTo(MULE)); assertThat("Bundle descriptor loader attributes defined in builder is not the expected", builder.getBundleDescriptorLoader().getAttributes(), equalTo(defaultBundleDescriptorAttributes(pomMock))); }
@Test public void setBuilderWithDefaultBundleDescriptorLoaderWrongIdValueTest() { MuleApplicationModel muleArtifactSpy = spy(muleArtifact); HashMap<String, Object> attributes = new HashMap<>(); attributes.put(ATTRIBUTE_1, Collections.emptyList()); attributes.put(ATTRIBUTE_2, Collections.emptyList()); doReturn(new MuleArtifactLoaderDescriptor(FAKE_ID, attributes)).when(muleArtifactSpy).getBundleDescriptorLoader(); Pom pomMock = mockPom(); MuleArtifactContentResolver resolverMock = mock(MuleArtifactContentResolver.class); when(resolverMock.getPom()).thenReturn(pomMock); builder = new MuleApplicationModel.MuleApplicationModelBuilder(); generator.setBuilderWithDefaultBundleDescriptorLoaderValue(builder, muleArtifactSpy, resolverMock); assertThat("Bundle descriptor loader id defined in builder is not the expected", builder.getBundleDescriptorLoader().getId(), equalTo(MULE)); attributes.putAll(defaultBundleDescriptorAttributes(pomMock)); assertThat("Bundle descriptor loader attributes defined in builder is not the expected", builder.getBundleDescriptorLoader().getAttributes(), equalTo(attributes)); }
@Test public void setBuilderWithDefaultBundleDescriptorLoaderValueTest() { Pom pomMock = mockPom(); MuleArtifactContentResolver resolverMock = mock(MuleArtifactContentResolver.class); when(resolverMock.getPom()).thenReturn(pomMock); generator.setBuilderWithDefaultBundleDescriptorLoaderValue(builder, muleArtifact, resolverMock); assertThat("Bundle descriptor loader id defined in builder is not the expected", builder.getBundleDescriptorLoader().getId(), equalTo(MULE)); assertThat("Bundle descriptor loader attributes defined in builder is not the expected", builder.getBundleDescriptorLoader().getAttributes(), equalTo(defaultBundleDescriptorAttributes(pomMock))); }