Skip to content

Commit 690c059

Browse files
committed
added junit test class (Issue #31)
1 parent d71eb96 commit 690c059

3 files changed

Lines changed: 183 additions & 8 deletions

File tree

pom.xml

Lines changed: 76 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@
6060
<org.imixs.workflow.version>6.1.4</org.imixs.workflow.version>
6161
<org.imixs.micro.version>1.0.0</org.imixs.micro.version>
6262
<microprofile.version>6.0</microprofile.version>
63+
<junit.jupiter.version>5.9.2</junit.jupiter.version>
64+
<mockito.version>5.8.0</mockito.version>
65+
<org.imixs.melman.version>2.1.0</org.imixs.melman.version>
6366
<custom.webResources>src/main/webapp</custom.webResources>
6467
<custom.unpackTypes>war</custom.unpackTypes>
6568
</properties>
@@ -416,7 +419,12 @@
416419
<groupId>org.apache.maven.plugins</groupId>
417420
<artifactId>maven-release-plugin</artifactId>
418421
</plugin>
419-
422+
<!-- Testing JUnit 5 -->
423+
<plugin>
424+
<groupId>org.apache.maven.plugins</groupId>
425+
<artifactId>maven-surefire-plugin</artifactId>
426+
<version>3.1.2</version>
427+
</plugin>
420428
</plugins>
421429

422430
<finalName>imixs-process-manager</finalName>
@@ -462,13 +470,6 @@
462470
<version>${org.imixs.workflow.version}</version>
463471
</dependency>
464472

465-
<!-- Imixs Micro -->
466-
<dependency>
467-
<groupId>org.imixs.workflow</groupId>
468-
<artifactId>imixs-micro-client</artifactId>
469-
<version>${org.imixs.micro.version}</version>
470-
</dependency>
471-
472473
<!-- Apache Lucene Core -->
473474
<dependency>
474475
<groupId>org.imixs.workflow</groupId>
@@ -481,5 +482,72 @@
481482
<artifactId>imixs-workflow-index-solr</artifactId> <version>${org.imixs.workflow.version}</version>
482483
</dependency> -->
483484

485+
486+
<!-- Testing -->
487+
<dependency>
488+
<groupId>org.imixs.workflow</groupId>
489+
<artifactId>imixs-melman</artifactId>
490+
<version>${org.imixs.melman.version}</version>
491+
<scope>test</scope>
492+
</dependency>
493+
<!-- JUnit 5 Dependencies -->
494+
<dependency>
495+
<groupId>org.junit.jupiter</groupId>
496+
<artifactId>junit-jupiter-api</artifactId>
497+
<version>${junit.jupiter.version}</version>
498+
<scope>test</scope>
499+
</dependency>
500+
<dependency>
501+
<groupId>org.junit.jupiter</groupId>
502+
<artifactId>junit-jupiter-engine</artifactId>
503+
<version>${junit.jupiter.version}</version>
504+
<scope>test</scope>
505+
</dependency>
506+
<!-- Mockito Dependencies -->
507+
<dependency>
508+
<groupId>org.mockito</groupId>
509+
<artifactId>mockito-core</artifactId>
510+
<version>${mockito.version}</version>
511+
<scope>test</scope>
512+
</dependency>
513+
<dependency>
514+
<groupId>org.mockito</groupId>
515+
<artifactId>mockito-junit-jupiter</artifactId>
516+
<version>${mockito.version}</version>
517+
<scope>test</scope>
518+
</dependency>
519+
<!-- Test dependencies -->
520+
<dependency>
521+
<groupId>jakarta.xml.bind</groupId>
522+
<artifactId>jakarta.xml.bind-api</artifactId>
523+
<version>3.0.0</version>
524+
<scope>test</scope>
525+
</dependency>
526+
<dependency>
527+
<groupId>org.eclipse.parsson</groupId>
528+
<artifactId>jakarta.json</artifactId>
529+
<version>1.1.1</version>
530+
<scope>test</scope>
531+
</dependency>
532+
<dependency>
533+
<groupId>org.glassfish.jaxb</groupId>
534+
<artifactId>jaxb-runtime</artifactId>
535+
<version>3.0.0</version>
536+
<scope>test</scope>
537+
</dependency>
538+
<dependency>
539+
<groupId>org.glassfish.jersey.media</groupId>
540+
<artifactId>jersey-media-jaxb</artifactId>
541+
<version>3.1.5</version>
542+
<scope>test</scope>
543+
</dependency>
544+
545+
<dependency>
546+
<groupId>org.glassfish.jersey.core</groupId>
547+
<artifactId>jersey-client</artifactId>
548+
<version>3.1.5</version>
549+
</dependency>
550+
551+
484552
</dependencies>
485553
</project>
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package org.imixs.workflow.rest;
2+
3+
import java.io.IOException;
4+
import java.net.HttpURLConnection;
5+
import java.net.URL;
6+
import java.util.logging.Logger;
7+
8+
/**
9+
* This JUnit Helper Class is used to skip integration tests.
10+
* <p>
11+
* This class tests if a connection to the rest service end-point can be
12+
* established.
13+
*
14+
* @author rsoika
15+
* @version 1.0
16+
*/
17+
public class IntegrationTest {
18+
19+
private String serviceEndpoint;
20+
private final static Logger logger = Logger.getLogger(IntegrationTest.class.getName());
21+
22+
public IntegrationTest(String uri) {
23+
this.serviceEndpoint = uri;
24+
}
25+
26+
public boolean connected() {
27+
try {
28+
HttpURLConnection urlConnection = (HttpURLConnection) new URL(serviceEndpoint).openConnection();
29+
urlConnection.connect();
30+
return true;
31+
} catch (IOException e) {
32+
logger.info("Integration Test skipped!");
33+
return false;
34+
}
35+
}
36+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
package org.imixs.workflow.rest;
2+
3+
import static org.junit.jupiter.api.Assertions.assertNotNull;
4+
import static org.junit.jupiter.api.Assertions.fail;
5+
import static org.junit.jupiter.api.Assumptions.assumeTrue;
6+
7+
import org.imixs.melman.BasicAuthenticator;
8+
import org.imixs.melman.RestAPIException;
9+
import org.imixs.melman.WorkflowClient;
10+
import org.imixs.workflow.ItemCollection;
11+
import org.junit.jupiter.api.BeforeEach;
12+
import org.junit.jupiter.api.Test;
13+
14+
/**
15+
* This test demonstrates the usage of the Melman Client API.
16+
*
17+
* @author rsoika
18+
*
19+
*/
20+
public class TestWorkfklowClient {
21+
22+
static String BASE_URL = "http://localhost:8080/api";
23+
static String USERID = "admin";
24+
static String PASSWORD = "adminadmin";
25+
26+
private IntegrationTest integrationTest = new IntegrationTest(BASE_URL);
27+
28+
WorkflowClient workflowCLient = null;
29+
30+
/**
31+
* The setup method just tests if the Rest API is available. If not the test
32+
* will be skipped!
33+
*
34+
* @throws Exception
35+
*/
36+
@BeforeEach
37+
public void setup() throws Exception {
38+
// Assumptions for integration tests
39+
assumeTrue(integrationTest.connected());
40+
workflowCLient = new WorkflowClient(BASE_URL);
41+
// create and register the default basic authenticator
42+
workflowCLient.registerClientRequestFilter(new BasicAuthenticator(USERID, PASSWORD));
43+
}
44+
45+
/**
46+
* test a client connection by creating a new workitem
47+
*
48+
* Note: this test is skipped if the rest api sever is not running!
49+
*/
50+
@Test
51+
public void testCreateWorkitem() {
52+
assertNotNull(workflowCLient);
53+
ItemCollection workitem = null;
54+
try {
55+
workitem = new ItemCollection();
56+
workitem.model("ticket-model-1.0.0").task(1000).event(10);
57+
workitem.replaceItemValue("type", "workitem");
58+
// add some data..
59+
workitem.replaceItemValue("_ticketid", "TEST-ID-001");
60+
workitem.replaceItemValue("_problem", "Just a JUnit Test");
61+
62+
// process workitem
63+
workitem = workflowCLient.processWorkitem(workitem);
64+
String uniqueID = workitem.getUniqueID();
65+
assertNotNull(uniqueID);
66+
67+
} catch (RestAPIException e) {
68+
fail(e.getMessage());
69+
}
70+
}
71+
}

0 commit comments

Comments
 (0)