1414 */
1515package 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+
1733import org .apache .log4j .Logger ;
1834import org .jboss .arquillian .container .test .api .Deployment ;
1935import org .jboss .arquillian .junit .Arquillian ;
2339import org .jboss .shrinkwrap .api .asset .EmptyAsset ;
2440import org .jboss .shrinkwrap .api .spec .WebArchive ;
2541import org .junit .After ;
26- import org .junit .Ignore ;
2742import org .junit .runner .RunWith ;
43+ import org .perfrepo .model .Alert ;
2844import org .perfrepo .model .Metric ;
2945import org .perfrepo .model .MetricComparator ;
3046import org .perfrepo .model .Test ;
47+ import org .perfrepo .model .TestExecution ;
48+ import org .perfrepo .model .Value ;
3149import 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 ;
3353import org .perfrepo .web .dao .DAO ;
3454import org .perfrepo .web .security .Secured ;
3555import org .perfrepo .web .service .TestService ;
3656import org .perfrepo .web .service .TestServiceBean ;
3757import org .perfrepo .web .service .exceptions .ServiceException ;
3858import 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
5467public 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}
0 commit comments