-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathAddVersionCommandIntegrationTest.java
More file actions
146 lines (125 loc) · 7.87 KB
/
AddVersionCommandIntegrationTest.java
File metadata and controls
146 lines (125 loc) · 7.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
package com.castsoftware.aip.console.tools;
import com.castsoftware.aip.console.tools.commands.AddVersionCommand;
import com.castsoftware.aip.console.tools.core.dto.DebugOptionsDto;
import com.castsoftware.aip.console.tools.core.dto.jobs.JobRequestBuilder;
import com.castsoftware.aip.console.tools.core.dto.jobs.JobState;
import com.castsoftware.aip.console.tools.core.dto.jobs.JobStatusWithSteps;
import com.castsoftware.aip.console.tools.core.exceptions.ApplicationServiceException;
import com.castsoftware.aip.console.tools.core.exceptions.JobServiceException;
import com.castsoftware.aip.console.tools.core.exceptions.PackagePathInvalidException;
import com.castsoftware.aip.console.tools.core.exceptions.UploadException;
import com.castsoftware.aip.console.tools.core.utils.Constants;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mockito;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner;
import picocli.CommandLine;
import java.io.File;
import java.util.Date;
import java.util.function.Function;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.when;
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE, classes = {AipConsoleToolsCliIntegrationTest.class})
@ActiveProfiles(TestConstants.PROFILE_INTEGRATION_TEST)
public class AddVersionCommandIntegrationTest extends AipConsoleToolsCliBaseTest {
@Autowired
private AddVersionCommand addVersionCommand;
@Override
protected void cleanupTestCommand() {
// ===================================
//command not recreated between test.
//So just clear the command as if it was brand newly created
//The best way is to run java -jar .\aip-console-tools-cli.jar add ...
// So that app creates new instances of commands.
// Still this woks fine renewing parameters values each time.
// Here only String types, but each test should set velues to requested ones
// ===================================
resetSharedOptions(addVersionCommand.getSharedOptions());
addVersionCommand.setApplicationGuid(null);
addVersionCommand.setApplicationName(null);
addVersionCommand.setBackupName(null);
addVersionCommand.setDomainName(null);
addVersionCommand.setFilePath(null);
addVersionCommand.setNodeName(null);
addVersionCommand.setVersionName(null);
}
@Test
public void testAddVersionCommand_FailToCreateApplication() throws ApplicationServiceException {
String[] args = defaultArgs;
// No existing application
when(applicationService.getOrCreateApplicationFromName(anyString(), anyBoolean(), anyString(), anyString(), anyBoolean())).thenReturn(null);
when(applicationService.getApplicationFromName(TestConstants.TEST_CREATRE_APP)).thenReturn(AipConsoleToolsCliBaseTest.simplifiedModeApp);
runStringArgs(addVersionCommand, args);
CommandLine.Model.CommandSpec spec = cliToTest.getCommandSpec();
assertThat(spec, is(notNullValue()));
assertThat(exitCode, is(Constants.RETURN_APPLICATION_NOT_FOUND));
}
@Test
public void testAddVersionCommand_SimplifiedDeliveryWithFileProvided() throws ApplicationServiceException {
String[] args = new String[]{"--apikey",
TestConstants.TEST_API_KEY, "--app-name=" + TestConstants.TEST_CREATRE_APP,
"-f", zippedSourcesPath.toString(),
"--version-name", TestConstants.TEST_VERSION_NAME,
"--domain-name", TestConstants.TEST_DOMAIN,
"--node-name", TestConstants.TEST_NODE};
// gives the existing application
when(applicationService.getOrCreateApplicationFromName(any(String.class), anyBoolean(), any(String.class), any(String.class), anyBoolean())).thenReturn(TestConstants.TEST_APP_GUID);
when(applicationService.getApplicationNameFromGuid(TestConstants.TEST_APP_GUID)).thenReturn(TestConstants.TEST_CREATRE_APP);
when(applicationService.getApplicationFromName(TestConstants.TEST_CREATRE_APP)).thenReturn(AipConsoleToolsCliBaseTest.simplifiedModeApp);
runStringArgs(addVersionCommand, args);
CommandLine.Model.CommandSpec spec = cliToTest.getCommandSpec();
assertThat(spec, is(notNullValue()));
assertThat(exitCode, is(Constants.RETURN_INPLACE_MODE_ERROR));
}
@Test
public void testAddVersionCommand_RunAddVersionJobCompleted() throws ApplicationServiceException, UploadException, JobServiceException, PackagePathInvalidException {
boolean verbose = true;
String[] args = new String[]{"--apikey",
TestConstants.TEST_API_KEY, "--app-name=" + TestConstants.TEST_CREATRE_APP,
"-f", sflPath.toString(),
"--version-name", TestConstants.TEST_VERSION_NAME,
"--domain-name", TestConstants.TEST_DOMAIN,
"--node-name", TestConstants.TEST_NODE};
// gives the existing application
when(applicationService.getOrCreateApplicationFromName(any(String.class), anyBoolean(), any(String.class), any(String.class), anyBoolean())).thenReturn(TestConstants.TEST_APP_GUID);
when(applicationService.getApplicationNameFromGuid(TestConstants.TEST_APP_GUID)).thenReturn(TestConstants.TEST_CREATRE_APP);
when(applicationService.getApplicationFromName(TestConstants.TEST_CREATRE_APP)).thenReturn(AipConsoleToolsCliBaseTest.simplifiedModeApp);
when(uploadService.uploadFileAndGetSourcePath(any(String.class), any(String.class), any(File.class))).thenReturn(sflPath.toString());
when(applicationService.applicationHasVersion(TestConstants.TEST_APP_GUID)).thenReturn(false);
when(applicationService.createDeliveryConfiguration(TestConstants.TEST_APP_GUID, sflPath.toString(), null, false)).thenReturn(TestConstants.TEST_DELIVERY_CONFIG_GUID);
when(jobsService.startAddVersionJob(any(JobRequestBuilder.class))).thenReturn(TestConstants.TEST_JOB_GUID);
DebugOptionsDto debugOptions = Mockito.mock(DebugOptionsDto.class);
when(debugOptions.isActivateAmtMemoryProfile()).thenReturn(false);
when(applicationService.getDebugOptions(TestConstants.TEST_APP_GUID)).thenReturn(debugOptions);
JobStatusWithSteps jobStatus = new JobStatusWithSteps();
jobStatus.setAppGuid(TestConstants.TEST_APP_GUID);
jobStatus.setState(JobState.COMPLETED);
jobStatus.setCreated(new Date());
jobStatus.setAppName(TestConstants.TEST_CREATRE_APP);
when(jobsService.pollAndWaitForJobFinished(TestConstants.TEST_JOB_GUID, Function.identity(), true)).thenReturn(jobStatus);
runStringArgs(addVersionCommand, args);
CommandLine.Model.CommandSpec spec = cliToTest.getCommandSpec();
assertThat(spec, is(notNullValue()));
assertThat(exitCode, is(Constants.RETURN_OK));
}
@Test
public void testAddVersionCommand() throws ApplicationServiceException {
String[] args = defaultArgs;
// gives the existing application
when(applicationService.getOrCreateApplicationFromName(anyString(), anyBoolean(), anyString(), anyString(), anyBoolean()))
.thenReturn(TestConstants.TEST_APP_GUID);
when(applicationService.getApplicationNameFromGuid(TestConstants.TEST_APP_GUID)).thenReturn(TestConstants.TEST_CREATRE_APP);
runStringArgs(addVersionCommand, args);
CommandLine.Model.CommandSpec spec = cliToTest.getCommandSpec();
assertThat(spec, is(notNullValue()));
}
}