-
Notifications
You must be signed in to change notification settings - Fork 2
/
RepositoriesTest.java
149 lines (126 loc) · 5.54 KB
/
RepositoriesTest.java
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
147
148
149
/*
* Copyright 2011-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.appng.application.manager.business;
import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import org.appng.api.FieldProcessor;
import org.appng.api.ProcessingException;
import org.appng.api.support.CallableAction;
import org.appng.api.support.CallableDataSource;
import org.appng.application.manager.form.RepositoryForm;
import org.appng.core.domain.RepositoryImpl;
import org.appng.core.model.RepositoryCacheFactory;
import org.appng.core.model.RepositoryMode;
import org.appng.core.model.RepositoryType;
import org.appng.testsupport.validation.XPathDifferenceHandler;
import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runners.MethodSorters;
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class RepositoriesTest extends AbstractTest {
private static final String REPO_PATH = new File("target").toPath().toUri().toString();
private static final String REPO_EVENT = "repositoryEvent";
@Test
public void testCreateRepository() throws Exception {
RepositoryForm repoForm = getRepository();
CallableAction callableAction = getAction(REPO_EVENT, "create").withParam(FORM_ACTION, "create")
.getCallableAction(repoForm);
FieldProcessor fieldProcessor = callableAction.perform();
validate(callableAction.getAction(), "-action");
validate(fieldProcessor.getMessages(), "-messages");
}
@Test
public void testCreateRepositoryNameExists() throws Exception {
RepositoryForm groupForm = getRepository();
CallableAction callableAction = getAction(REPO_EVENT, "create").withParam(FORM_ACTION, "create")
.getCallableAction(groupForm);
callableAction.perform();
validate(callableAction.getAction());
}
@Test
public void testDeleteRepository() throws ProcessingException, IOException {
createRepository();
CallableAction callableAction = getAction(REPO_EVENT, "delete").withParam("repositoryid", "2")
.withParam("form_action", "delete-repository").getCallableAction(null);
FieldProcessor fieldProcessor = callableAction.perform();
validate(fieldProcessor.getMessages());
}
@Test
public void testShowRepository() throws Exception {
CallableDataSource siteDatasource = getDataSource("repository").withParam("repositoryid", "1")
.getCallableDataSource();
siteDatasource.perform("test");
XPathDifferenceHandler differenceListener = new XPathDifferenceHandler(false);
differenceListener.ignoreDifference("/datasource[1]/data[1]/result[1]/field[3]/value[1]/text()[1]");
differenceListener.ignoreDifference("/datasource[1]/data[1]/result[1]/field[4]/value[1]/text()[1]");
validate(siteDatasource.getDatasource(), differenceListener);
}
@Test
public void testShowRepositories() throws Exception {
createRepository();
addParameter("sortRepositories", "name:desc");
initParameters();
CallableDataSource siteDatasource = getDataSource("repositories").getCallableDataSource();
siteDatasource.perform("test");
XPathDifferenceHandler differenceListener = new XPathDifferenceHandler(false);
differenceListener.ignoreDifference("/datasource[1]/data[1]/resultset[1]/result[1]/field[5]/value[1]/text()[1]");
differenceListener.ignoreDifference("/datasource[1]/data[1]/resultset[1]/result[2]/field[5]/value[1]/text()[1]");
validate(siteDatasource.getDatasource(), differenceListener);
}
@Test
public void testUpdateRepository() throws Exception {
RepositoryCacheFactory.init(null, null, null, null, false);
RepositoryForm repoForm = getRepository();
CallableAction callableAction = getAction(REPO_EVENT, "update").withParam("repositoryid", "1")
.withParam(FORM_ACTION, "update").getCallableAction(repoForm);
XPathDifferenceHandler differenceListener = new XPathDifferenceHandler(false);
differenceListener.ignoreDifference("/action[1]/data[1]/result[1]/field[3]/value[1]/text()[1]");
differenceListener.ignoreDifference("/action[1]/data[1]/result[1]/field[4]/value[1]/text()[1]");
FieldProcessor fieldProcessor = callableAction.perform();
validate(callableAction.getAction(), "-action", differenceListener);
validate(fieldProcessor.getMessages(), "-messages");
}
private RepositoryForm getRepository() {
RepositoryImpl repo = new RepositoryImpl();
RepositoryForm repoForm = new RepositoryForm(repo);
repo.setName("Local");
repo.setDescription("local repo");
repo.setRepositoryMode(RepositoryMode.ALL);
repo.setRepositoryType(RepositoryType.LOCAL);
try {
repo.setUri(new URI(REPO_PATH));
} catch (URISyntaxException e) {
// ignore
}
return repoForm;
}
private void createRepository() {
RepositoryImpl realRepository = new RepositoryImpl();
realRepository.setName("Delete me");
realRepository.setDescription("delete me");
realRepository.setActive(true);
realRepository.setRepositoryMode(RepositoryMode.ALL);
realRepository.setRepositoryType(RepositoryType.LOCAL);
try {
realRepository.setUri(new URI(REPO_PATH));
} catch (URISyntaxException e) {
// ignore
}
repoRepository.save(realRepository);
}
}