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.IOException;
25 import java.io.PrintStream;
26 import java.util.Arrays;
27 import java.util.HashMap;
28 import java.util.Map;
29 import java.util.logging.LogManager;
30 import java.util.logging.Logger;
31
32 import org.apache.maven.artifact.Artifact;
33 import org.apache.maven.model.Build;
34 import org.apache.maven.project.MavenProject;
35 import org.easymock.EasyMock;
36 import org.junit.After;
37 import org.junit.Before;
38 import org.junit.BeforeClass;
39 import org.junit.Ignore;
40 import org.junit.Test;
41
42 public class XCodeManagerTest extends XCodeTest
43 {
44
45 private static File projectDirectory;
46
47
48
49
50
51 private static Logger logger;
52
53 @BeforeClass
54 public static void setup()
55 {
56 projectDirectory = new File(new File(".").getAbsoluteFile(), "target/tests/"
57 + XCodeManagerTest.class.getName());
58 logger = new XCodePluginLogger();
59 LogManager.getLogManager().addLogger(logger);
60 }
61
62 @Before
63 public void ensureCleanProjectDirectoryAndFilterPom() throws Exception
64 {
65 ensureCleanProjectDirectoryAndFilterPom(projectDirectory);
66 }
67
68 @After
69 public void cleanupProjectDirectory() throws Exception
70 {
71 MacFileUtil.deleteDirectory(projectDirectory);
72 }
73
74 @Test
75 public void straightForwardTestBuildLibWithoutPredecessors() throws Exception
76 {
77 Map<String, String> managedOptions = new HashMap<String, String>();
78 managedOptions.put(Options.ManagedOption.PROJECT.getOptionName(), "MyLibrary.xcodeproj");
79 managedOptions.put(Options.ManagedOption.CONFIGURATION.getOptionName(), "Release");
80 managedOptions.put(Options.ManagedOption.SDK.getOptionName(), "iphoneos");
81 Options options = new Options(null, managedOptions);
82 final XCodeContext context = new XCodeContext(Arrays.asList("clean", "build"), new File(projectDirectory,
83 "MyLibrary/src/xcode"), System.out, null, options);
84
85 MavenProject mavenProject = EasyMock.createMock(MavenProject.class);
86 Build build = EasyMock.createMock(Build.class);
87
88 EasyMock.expect(mavenProject.getBuild()).andStubReturn(build);
89 EasyMock.expect(build.getDirectory()).andStubReturn("");
90
91 EasyMock.expect(mavenProject.getCompileArtifacts()).andStubReturn(Arrays.asList((Artifact) null));
92
93 EasyMock.replay(build, mavenProject);
94
95
96
97
98
99 new XCodeManager().callXcodeBuild(context);
100 }
101
102
103
104
105
106 @Ignore
107
108 @Test
109 public void invalidConfigurationTest() throws Exception
110 {
111 MavenProject mavenProject = EasyMock.createMock(MavenProject.class);
112 Build build = EasyMock.createMock(Build.class);
113
114 EasyMock.expect(mavenProject.getBuild()).andStubReturn(build);
115 EasyMock.expect(build.getDirectory()).andStubReturn("");
116
117 EasyMock.expect(mavenProject.getCompileArtifacts()).andStubReturn(Arrays.asList((Artifact) null));
118
119 EasyMock.replay(build, mavenProject);
120
121 Map<String, String> managedOptions = new HashMap<String, String>();
122 managedOptions.put(Options.ManagedOption.CONFIGURATION.getOptionName(), "NON-EXISTNG_CONFIGURATION");
123 managedOptions.put(Options.ManagedOption.SDK.getOptionName(), "iphoneos");
124
125 Options options = new Options(null, managedOptions);
126 final XCodeContext context = new XCodeContext(Arrays.asList("clean", "build"), projectDirectory, System.out, null,
127 options);
128 new XCodeManager().callXcodeBuild(context);
129
130 }
131
132 @Test(expected = IOException.class)
133 public void damagedPrintStreamProvidedTest() throws Exception
134 {
135 MavenProject mavenProject = EasyMock.createMock(MavenProject.class);
136 Build build = EasyMock.createMock(Build.class);
137
138 EasyMock.expect(mavenProject.getBuild()).andStubReturn(build);
139 EasyMock.expect(build.getDirectory()).andStubReturn("");
140
141 EasyMock.expect(mavenProject.getCompileArtifacts()).andStubReturn(Arrays.asList((Artifact) null));
142
143 EasyMock.replay(build, mavenProject);
144
145 Map<String, String> managedOptions = new HashMap<String, String>();
146 managedOptions.put(Options.ManagedOption.CONFIGURATION.getOptionName(), "Release");
147 managedOptions.put(Options.ManagedOption.SDK.getOptionName(), "iphoneos");
148 managedOptions.put(Options.ManagedOption.PROJECT.getOptionName(), "MyLibrary.xcodeproj");
149
150 Options options = new Options(null, managedOptions);
151 final XCodeContext context = new XCodeContext(Arrays.asList("clean", "build"), projectDirectory, new PrintStream(
152 new ByteArrayOutputStream()) {
153
154 @Override
155 public void write(byte[] buf, int off, int len)
156 {
157 setError();
158 }
159 }, null, options);
160 new XCodeManager().callXcodeBuild(context);
161
162 }
163 }