1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package com.sap.prd.mobile.ios.mios;
21
22 import java.io.ByteArrayOutputStream;
23 import java.io.File;
24 import java.io.FileInputStream;
25 import java.util.ArrayList;
26 import java.util.List;
27
28 import junit.framework.Assert;
29
30 import org.apache.commons.io.IOUtils;
31 import org.apache.maven.it.util.IOUtil;
32 import org.junit.Test;
33
34 import com.sap.prd.mobile.ios.mios.versioninfo.v_1_2_2.Dependency;
35
36 public class VersionInfoManagerTest
37 {
38
39 @Test
40 public void testStraightForward() throws Exception
41 {
42 Dependency dependency = VersionInfoXmlManager.parseDependency(new File("src/test/resources/validXML.xml"));
43
44 Assert.assertEquals("com.sap.ondevice.production.ios.tests", dependency.getCoordinates().getGroupId());
45 Assert.assertEquals("MyApp", dependency.getCoordinates().getArtifactId());
46 Assert.assertEquals("1.0.0", dependency.getCoordinates().getVersion());
47
48 Assert.assertEquals("scm:perforce:PERFORCEHOST:9999://MY_DEPOT_PATH", dependency.getScm().getConnection());
49 Assert.assertEquals("4711", dependency.getScm().getRevision());
50
51
52 }
53
54 @Test
55 public void testOldVersionInfoFormatAlpha20() throws Exception
56 {
57 List<Dependency> dependencies = new ArrayList<Dependency>();
58 dependencies.add(VersionInfoXmlManager.parseDependency(new File("src/test/resources/versions-alpha-20.xml")));
59
60 final ByteArrayOutputStream os = new ByteArrayOutputStream();
61
62 try {
63
64 new VersionInfoXmlManager().createVersionInfoFile("com.sap.ondevice.production.ios.tests", "MyApp", "1.0.0",
65 new File(".", "src/test/resources/sync.info"), dependencies, os);
66
67 Assert.assertEquals(IOUtil.toString(new FileInputStream(new File(
68 "src/test/resources/versionInfoFileRewritten-alpha-20.xml").getAbsoluteFile()), "UTF-8"),
69 IOUtil.toString(os.toByteArray(), "UTF-8"));
70 }
71 finally {
72 IOUtils.closeQuietly(os);
73 }
74 }
75
76 @Test
77 public void testOldVersionInfoFormatBeta2() throws Exception
78 {
79 List<Dependency> dependencies = new ArrayList<Dependency>();
80 dependencies.add(VersionInfoXmlManager.parseDependency(new File("src/test/resources/versions-beta-2.xml")));
81
82 final ByteArrayOutputStream os = new ByteArrayOutputStream();
83
84 try {
85
86 new VersionInfoXmlManager().createVersionInfoFile("com.sap.ondevice.production.ios.tests", "MyApp", "1.0.0",
87 new File(".", "src/test/resources/sync.info"), dependencies, os);
88
89 Assert.assertEquals(IOUtil.toString(new FileInputStream(new File(
90 "src/test/resources/versionInfoFileRewritten-beta-2.xml").getAbsoluteFile()), "UTF-8"),
91 IOUtil.toString(os.toByteArray(), "UTF-8"));
92 }
93 finally {
94 IOUtils.closeQuietly(os);
95 }
96 }
97
98 @Test
99 public void testOldVersionInfoFormatBeta3() throws Exception
100 {
101 List<Dependency> dependencies = new ArrayList<Dependency>();
102 dependencies.add(VersionInfoXmlManager.parseDependency(new File("src/test/resources/versions-beta-3.xml")));
103
104 final ByteArrayOutputStream os = new ByteArrayOutputStream();
105
106 try {
107
108 new VersionInfoXmlManager().createVersionInfoFile("com.sap.ondevice.production.ios.tests", "MyApp", "1.0.0",
109 new File(".", "src/test/resources/sync.info"), dependencies, os);
110
111 Assert.assertEquals(IOUtil.toString(new FileInputStream(new File(
112 "src/test/resources/versionInfoFileRewritten-beta-3.xml").getAbsoluteFile()), "UTF-8"),
113 IOUtil.toString(os.toByteArray(), "UTF-8"));
114 }
115 finally {
116 IOUtils.closeQuietly(os);
117 }
118 }
119
120 @Test
121 public void testCreateVersionInfoStringGit() throws Exception {
122 final ByteArrayOutputStream byteOs = new ByteArrayOutputStream();
123 try {
124 new VersionInfoXmlManager().createVersionInfoFile("my.group.id", "my.artifact.id", "1.0.0", new File("src/test/resources/git-sync.info"), new ArrayList<Dependency>(), byteOs);
125 } finally {
126 byteOs.close();
127 }
128 Assert.assertEquals(IOUtil.toString(new FileInputStream("src/test/resources/git-versions.xml.expected")), new String(byteOs.toByteArray()));
129 };
130
131 }