Skip to content
This repository was archived by the owner on Feb 22, 2024. It is now read-only.

Commit efb1911

Browse files
authored
Merge pull request #85 from vjuranek/PERFREPO-273
[PERFREPO-273] Update value instead of recreating it
2 parents 6a52871 + 0757b14 commit efb1911

File tree

7 files changed

+110
-35
lines changed

7 files changed

+110
-35
lines changed

README.md

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,14 @@ Also you have to add test datasource `PerfRepoTestDS`into the WildFly, ideally p
123123
</datasource>
124124
```
125125

126-
127-
128-
129-
126+
For testing session bean, authentication is require and thus you have to also add appropriate security domain:
127+
```xml
128+
<security-domain name="Arquillian-Testing" cache-type="default">
129+
<authentication>
130+
<login-module code="UsersRoles" flag="required">
131+
<module-option name="usersProperties" value="users.properties"/>
132+
<module-option name="rolesProperties" value="roles.properties"/>
133+
</login-module>
134+
</authentication>
135+
</security-domain>
136+
```

web/pom.xml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,26 @@
294294
</execution>
295295
</executions>
296296
</plugin>
297+
298+
<!-- for tests -->
299+
<plugin>
300+
<groupId>org.apache.maven.plugins</groupId>
301+
<artifactId>maven-dependency-plugin</artifactId>
302+
<executions>
303+
<execution>
304+
<id>copy-test-libs</id>
305+
<phase>process-test-resources</phase>
306+
<configuration>
307+
<includeScope>test</includeScope>
308+
<outputDirectory>${project.build.directory}/test-libs</outputDirectory>
309+
<stripVersion>true</stripVersion>
310+
</configuration>
311+
<goals>
312+
<goal>copy-dependencies</goal>
313+
</goals>
314+
</execution>
315+
</executions>
316+
</plugin>
297317

298318
</plugins>
299319

web/src/main/java/org/perfrepo/web/service/TestServiceBean.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -860,12 +860,9 @@ private void validateTestExecution(TestExecution testExecution) throws ServiceEx
860860
* @throws ServiceException
861861
*/
862862
private void updateValues(TestExecution freshTestExecution, TestExecution updatedTestExecution) throws ServiceException {
863-
freshTestExecution.getValues().stream().forEach(valueDAO::remove);
864-
freshTestExecution.setValues(new ArrayList<>());
865-
866863
for (Value value: updatedTestExecution.getValues()) {
867864
value.setTestExecution(freshTestExecution);
868-
addValue(value);
865+
updateValue(value);
869866
}
870867
}
871868

web/src/test/java/org/perfrepo/test/JBossLoginContextFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ private AppConfigurationEntry createClientLoginModuleConfigEntry() {
111111
* @return the configured LoginContext.
112112
*/
113113
public static LoginContext createLoginContext(final String username, final String password) throws LoginException {
114-
final String configurationName = "Arquillian Testing";
114+
final String configurationName = "Arquillian-Testing";
115115

116116
CallbackHandler cbh = new JBossLoginContextFactory.NamePasswordCallbackHandler(username, password);
117117
Configuration config = new JBossJaasConfiguration(configurationName);

web/src/test/java/org/perfrepo/test/TestServiceBeanTest.java

Lines changed: 75 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,22 @@
1414
*/
1515
package org.perfrepo.test;
1616

17+
import static org.junit.Assert.assertEquals;
18+
import static org.junit.Assert.assertTrue;
19+
20+
import java.io.File;
21+
import java.security.PrivilegedAction;
22+
import java.time.Instant;
23+
import java.util.Arrays;
24+
import java.util.Collection;
25+
import java.util.Date;
26+
import java.util.concurrent.Callable;
27+
28+
import javax.ejb.EJBException;
29+
import javax.inject.Inject;
30+
import javax.security.auth.Subject;
31+
import javax.security.auth.login.LoginContext;
32+
1733
import org.apache.log4j.Logger;
1834
import org.jboss.arquillian.container.test.api.Deployment;
1935
import org.jboss.arquillian.junit.Arquillian;
@@ -23,55 +39,55 @@
2339
import org.jboss.shrinkwrap.api.asset.EmptyAsset;
2440
import org.jboss.shrinkwrap.api.spec.WebArchive;
2541
import org.junit.After;
26-
import org.junit.Ignore;
2742
import org.junit.runner.RunWith;
43+
import org.perfrepo.model.Alert;
2844
import org.perfrepo.model.Metric;
2945
import org.perfrepo.model.MetricComparator;
3046
import org.perfrepo.model.Test;
47+
import org.perfrepo.model.TestExecution;
48+
import org.perfrepo.model.Value;
3149
import org.perfrepo.model.builder.TestBuilder;
32-
import org.perfrepo.model.to.TestExecutionSearchTO;
50+
import org.perfrepo.model.builder.TestExecutionBuilder;
51+
import org.perfrepo.web.alerting.ConditionChecker;
52+
import org.perfrepo.web.controller.TestController;
3353
import org.perfrepo.web.dao.DAO;
3454
import org.perfrepo.web.security.Secured;
3555
import org.perfrepo.web.service.TestService;
3656
import org.perfrepo.web.service.TestServiceBean;
3757
import org.perfrepo.web.service.exceptions.ServiceException;
3858
import org.perfrepo.web.session.TEComparatorSession;
39-
40-
import javax.ejb.EJBException;
41-
import javax.inject.Inject;
42-
import javax.security.auth.Subject;
43-
import javax.security.auth.login.LoginContext;
44-
import java.security.PrivilegedAction;
45-
import java.util.concurrent.Callable;
59+
import org.perfrepo.web.util.MultiValue;
4660

4761
/**
4862
* Tests for {@link TestServiceBean}
4963
*
5064
* @author Michal Linhard (mlinhard@redhat.com)
5165
*/
5266
@RunWith(Arquillian.class)
53-
@Ignore
5467
public class TestServiceBeanTest {
5568

5669
private static final Logger log = Logger.getLogger(TestServiceBeanTest.class);
5770

58-
private static String testUserRole = System.getProperty("perfrepo.test.role", "testuser");
71+
private static String testUserRole = System.getProperty("perfrepo.test.role", "perfrepouser");
5972

6073
@Deployment
6174
public static Archive<?> createDeployment() {
6275
WebArchive war = ShrinkWrap.create(WebArchive.class, "test.war");
63-
war.addPackage(DAO.class.getPackage());
64-
war.addPackage(TestService.class.getPackage());
76+
war.addPackages(true, Alert.class.getPackage());
77+
war.addPackages(true, TestService.class.getPackage());
78+
war.addPackages(true, TestController.class.getPackage());
6579
war.addPackage(Secured.class.getPackage());
6680
war.addPackage(TEComparatorSession.class.getPackage());
67-
war.addPackage(Test.class.getPackage());
68-
war.addPackage(TestBuilder.class.getPackage());
69-
war.addPackage(TestExecutionSearchTO.class.getPackage());
7081
war.addPackage(JBossLoginContextFactory.class.getPackage());
82+
war.addPackage(ConditionChecker.class.getPackage());
83+
war.addPackage(MultiValue.class.getPackage());
84+
war.addPackage(DAO.class.getPackage());
85+
war.addPackages(true, Alert.class.getPackage());
86+
war.addAsLibrary(new File("target/test-libs/antlr-runtime.jar"));
87+
war.addAsLibrary(new File("target/test-libs/maven-artifact.jar"));
7188
war.addAsResource("test-persistence.xml", "META-INF/persistence.xml");
7289
war.addAsResource("users.properties");
7390
war.addAsResource("roles.properties");
74-
war.addAsWebInfResource("test-jbossas-ds.xml");
7591
war.addAsWebInfResource(EmptyAsset.INSTANCE, ArchivePaths.create("beans.xml"));
7692
return war;
7793
}
@@ -130,6 +146,15 @@ public Exception run() {
130146
protected TestBuilder test(String nameAndUid) {
131147
return Test.builder().name(nameAndUid).groupId(testUserRole).uid(nameAndUid).description("description for " + nameAndUid);
132148
}
149+
150+
protected TestExecutionBuilder testExec(String nameAndUid, boolean createTest) throws Exception {
151+
if (createTest) {
152+
testService.createTest(test(nameAndUid).description("test test").metric("metric1", MetricComparator.HB, "").build());
153+
}
154+
//test must exists otherwise it will fail anyway
155+
Test test = testService.getTestByUID(nameAndUid);
156+
return TestExecution.builder().name(nameAndUid).testId(test.getId()).started(Date.from(Instant.now())).tag("tag");
157+
}
133158

134159
@org.junit.Test
135160
public void testCreateDeleteTest() throws Exception {
@@ -192,7 +217,7 @@ public void testAddMetric() throws Exception {
192217
public Void call() throws Exception {
193218
assert testService.getAllFullTests().isEmpty();
194219
Test test = testService.createTest(test("test1").metric("metric1", "desc").metric("metric2", "desc").build());
195-
testService.addMetric(test, Metric.builder().name("metric3").description("metric 3").build());
220+
testService.addMetric(test, Metric.builder().name("metric3").description("metric 3").comparator(MetricComparator.HB).build());
196221
assert testService.getAllFullTests().size() == 1;
197222
return null;
198223
}
@@ -207,7 +232,7 @@ public Void call() throws Exception {
207232
assert testService.getAllFullTests().isEmpty();
208233
Test createdTest = testService.createTest(test("test1").metric("A", "desc").build());
209234
try {
210-
testService.addMetric(createdTest, Metric.builder().name("A").description("desc").build());
235+
testService.addMetric(createdTest, Metric.builder().name("A").description("desc").comparator(MetricComparator.HB).build());
211236
assert false;
212237
} catch (ServiceException e) {
213238
// ok
@@ -246,7 +271,7 @@ public Void call() throws Exception {
246271
testService.createTest(test("test1").metric("A", "desc").build());
247272
Test test2 = testService.createTest(test("test2").metric("B", "desc").build());
248273
try {
249-
testService.addMetric(test2, Metric.builder().name("A").description("desc").build());
274+
testService.addMetric(test2, Metric.builder().name("A").description("desc").comparator(MetricComparator.HB).build());
250275
assert false;
251276
} catch (ServiceException e) {
252277
// ok
@@ -256,4 +281,34 @@ public Void call() throws Exception {
256281
}
257282
});
258283
}
284+
285+
@org.junit.Test //PERFREPO-273
286+
public void testUpdateTestExecutionValue() throws Exception {
287+
asUser(testUserRole, new Callable<Void>() {
288+
@Override
289+
public Void call() throws Exception {
290+
assertTrue(testService.getAllFullTests().isEmpty());
291+
testService.createTestExecution(testExec("test1", true).value("metric1", 100.0).build());
292+
Collection<TestExecution> execs = testService.getTestExecutions(Arrays.asList("tag"), Arrays.asList("test1"));
293+
assertEquals(1, execs.size());
294+
TestExecution te = execs.iterator().next();
295+
Collection<Value> values = te.getValues();
296+
assertEquals(1, values.size());
297+
Value val = values.iterator().next();
298+
assertEquals(100.0, val.getResultValue().doubleValue(), 0.001);
299+
300+
TestExecution newTe = te.clone();
301+
Value newVal = val.clone();
302+
newVal.setResultValue(200.0);
303+
newTe.setValues(Arrays.asList(newVal));
304+
testService.updateTestExecution(newTe);
305+
execs = testService.getTestExecutions(Arrays.asList("tag"), Arrays.asList("test1"));
306+
assertEquals(1, execs.size());
307+
values = execs.iterator().next().getValues();
308+
assertEquals(1, values.size());
309+
assertEquals(200.0, values.iterator().next().getResultValue().doubleValue(), 0.001);
310+
return null;
311+
}
312+
});
313+
}
259314
}
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
1+
perfrepouser=perfrepouser
12
testuser=testuser,perfrepouser
2-
testuser1=testuser1,perfrepouser
3-
testuser2=testuser2,perfrepouser
4-
testuser3=testuser3,perfrepouser
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
1+
perfrepouser=perfrepouser
12
testuser=testuser
2-
testuser1=testuser1
3-
testuser2=testuser2
4-
testuser3=testuser3

0 commit comments

Comments
 (0)