You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ace.apache.org by ma...@apache.org on 2012/04/10 09:57:05 UTC
svn commit: r1311620 - in /ace/trunk/ace-builder/src:
main/java/org/apache/ace/builder/DeploymentPackageBuilder.java
test/java/org/apache/ace/builder/DeploymentPackageBuilderTest.java
Author: marrs
Date: Tue Apr 10 07:57:04 2012
New Revision: 1311620
URL: http://svn.apache.org/viewvc?rev=1311620&view=rev
Log:
Added some getters to the builder, refactored the tests to be more robust (and fixed them, because they were failing).
Modified:
ace/trunk/ace-builder/src/main/java/org/apache/ace/builder/DeploymentPackageBuilder.java
ace/trunk/ace-builder/src/test/java/org/apache/ace/builder/DeploymentPackageBuilderTest.java
Modified: ace/trunk/ace-builder/src/main/java/org/apache/ace/builder/DeploymentPackageBuilder.java
URL: http://svn.apache.org/viewvc/ace/trunk/ace-builder/src/main/java/org/apache/ace/builder/DeploymentPackageBuilder.java?rev=1311620&r1=1311619&r2=1311620&view=diff
==============================================================================
--- ace/trunk/ace-builder/src/main/java/org/apache/ace/builder/DeploymentPackageBuilder.java (original)
+++ ace/trunk/ace-builder/src/main/java/org/apache/ace/builder/DeploymentPackageBuilder.java Tue Apr 10 07:57:04 2012
@@ -50,18 +50,18 @@ import java.util.zip.ZipEntry;
* and resource processors first and then all artifacts.
*/
public class DeploymentPackageBuilder {
- private static final int BUFFER_SIZE = 32 * 1024;
private static final String PREFIX_BUNDLE = "bundle-";
private static final String PREFIX_ARTIFACT = "artifact-";
- private final String m_name;
+ private static final int BUFFER_SIZE = 32 * 1024;
+ private final String m_symbolicName;
private final String m_version;
- private int m_id = 1;
private final List<ArtifactData> m_bundles = new ArrayList<ArtifactData>();
private final List<ArtifactData> m_processors = new ArrayList<ArtifactData>();
private final List<ArtifactData> m_artifacts = new ArrayList<ArtifactData>();
+ private int m_id = 1;
- private DeploymentPackageBuilder(String name, String version) {
- m_name = name;
+ private DeploymentPackageBuilder(String symbolicName, String version) {
+ m_symbolicName = symbolicName;
m_version = version;
}
@@ -137,8 +137,8 @@ public class DeploymentPackageBuilder {
}
/** Returns the symbolic name of the deployment package. */
- public String getName() {
- return m_name;
+ public String getSymbolicName() {
+ return m_symbolicName;
}
/** Returns the version of the deployment package. */
@@ -209,7 +209,7 @@ public class DeploymentPackageBuilder {
Manifest manifest = new Manifest();
Attributes main = manifest.getMainAttributes();
main.putValue("Manifest-Version", "1.0");
- main.putValue("DeploymentPackage-SymbolicName", m_name);
+ main.putValue("DeploymentPackage-SymbolicName", m_symbolicName);
main.putValue("DeploymentPackage-Version", m_version);
for (ArtifactData file : files) {
@@ -260,7 +260,6 @@ public class DeploymentPackageBuilder {
}
}
}
-
private synchronized int getUniqueID() {
return m_id++;
}
Modified: ace/trunk/ace-builder/src/test/java/org/apache/ace/builder/DeploymentPackageBuilderTest.java
URL: http://svn.apache.org/viewvc/ace/trunk/ace-builder/src/test/java/org/apache/ace/builder/DeploymentPackageBuilderTest.java?rev=1311620&r1=1311619&r2=1311620&view=diff
==============================================================================
--- ace/trunk/ace-builder/src/test/java/org/apache/ace/builder/DeploymentPackageBuilderTest.java (original)
+++ ace/trunk/ace-builder/src/test/java/org/apache/ace/builder/DeploymentPackageBuilderTest.java Tue Apr 10 07:57:04 2012
@@ -18,10 +18,13 @@
*/
package org.apache.ace.builder;
+import static org.apache.ace.test.utils.TestUtils.UNIT;
+
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.net.URL;
+import java.util.Collection;
import java.util.Map;
import java.util.jar.Attributes;
import java.util.jar.JarInputStream;
@@ -31,8 +34,6 @@ import java.util.jar.Manifest;
import org.testng.Assert;
import org.testng.annotations.Test;
-import static org.apache.ace.test.utils.TestUtils.UNIT;
-
public class DeploymentPackageBuilderTest {
@Test(groups = { UNIT })
public void testEmptyDeploymentPackage() throws Exception {
@@ -70,10 +71,10 @@ public class DeploymentPackageBuilderTes
Assert.assertEquals(name, m.getMainAttributes().getValue("DeploymentPackage-SymbolicName"));
Assert.assertEquals(version, m.getMainAttributes().getValue("DeploymentPackage-Version"));
Assert.assertEquals(1, m.getEntries().size());
- Attributes attributes = m.getEntries().get(tempBundleFile.getName());
- Assert.assertNotNull(attributes);
- Assert.assertEquals(bundleSymbolicName, attributes.getValue("Bundle-SymbolicName"));
- Assert.assertEquals(bundleVersion, attributes.getValue("Bundle-Version"));
+ contains(m.getEntries().values(),
+ "Bundle-SymbolicName", bundleSymbolicName,
+ "Bundle-Version", bundleVersion
+ );
}
@Test(groups = { UNIT })
@@ -101,13 +102,14 @@ public class DeploymentPackageBuilderTes
Assert.assertEquals(name, m.getMainAttributes().getValue("DeploymentPackage-SymbolicName"));
Assert.assertEquals(version, m.getMainAttributes().getValue("DeploymentPackage-Version"));
Assert.assertEquals(2, m.getEntries().size());
- Attributes attributes = m.getEntries().get(tempBundleFile.getName());
- Assert.assertNotNull(attributes);
- Assert.assertEquals(bundleSymbolicName, attributes.getValue("Bundle-SymbolicName"));
- Assert.assertEquals(bundleVersion, attributes.getValue("Bundle-Version"));
- attributes = m.getEntries().get(tempBundleFile2.getName());
- Assert.assertEquals(bundleSymbolicName2, attributes.getValue("Bundle-SymbolicName"));
- Assert.assertEquals(bundleVersion2, attributes.getValue("Bundle-Version"));
+ contains(m.getEntries().values(),
+ "Bundle-SymbolicName", bundleSymbolicName,
+ "Bundle-Version", bundleVersion
+ );
+ contains(m.getEntries().values(),
+ "Bundle-SymbolicName", bundleSymbolicName2,
+ "Bundle-Version", bundleVersion2
+ );
}
@Test(groups = { UNIT })
@@ -136,16 +138,17 @@ public class DeploymentPackageBuilderTes
Assert.assertEquals(version, m.getMainAttributes().getValue("DeploymentPackage-Version"));
Map<String, Attributes> entries = m.getEntries();
Assert.assertEquals(2, entries.size());
- Attributes attributes = entries.get(tempBundleFile.getName());
- Assert.assertNotNull(attributes);
- Assert.assertEquals(bundleSymbolicName, attributes.getValue("Bundle-SymbolicName"));
- Assert.assertEquals(bundleVersion, attributes.getValue("Bundle-Version"));
- Assert.assertEquals("true", attributes.getValue("DeploymentPackage-Customizer"));
- Assert.assertEquals(pid, attributes.getValue("Deployment-ProvidesResourceProcessor"));
- attributes = entries.get(tempArtifactFile.getName());
- Assert.assertEquals(pid, attributes.getValue("Resource-Processor"));
+ contains(entries.values(),
+ "Bundle-SymbolicName", bundleSymbolicName,
+ "Bundle-Version", bundleVersion,
+ "DeploymentPackage-Customizer", "true",
+ "Deployment-ProvidesResourceProcessor", pid
+ );
+ contains(entries.values(),
+ "Resource-Processor", pid
+ );
}
-
+
@Test(groups = { UNIT }, expectedExceptions = { Exception.class })
public void testResourceWithoutProcessorDeploymentPackage() throws Exception {
File tempFile = File.createTempFile("output-", ".jar");
@@ -231,4 +234,20 @@ public class DeploymentPackageBuilderTes
}
}
}
+
+ private void contains(Collection<Attributes> list, String... keysAndValues) {
+ for (Attributes attributes : list) {
+ boolean found = true;
+ for (int i = 0; i < keysAndValues.length; i += 2) {
+ if (!keysAndValues[i + 1].equals(attributes.getValue(keysAndValues[i]))) {
+ found = false;
+ break;
+ }
+ }
+ if (found) {
+ return;
+ }
+ }
+ throw new IllegalStateException("Could not find entry in list.");
+ }
}