Skip to content

Commit

Permalink
Merge pull request #15 from WolfSchlegel/TRUNK-5817
Browse files Browse the repository at this point in the history
Trunk 5817: Migrate web and webapp package tests to Junit 5
  • Loading branch information
achilep committed Aug 4, 2020
2 parents 607e1aa + 729a648 commit f21c16b
Show file tree
Hide file tree
Showing 14 changed files with 294 additions and 97 deletions.
24 changes: 24 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "daily"
pull-request-branch-name:
separator: "-"
reviewers:
- "openmrs/dev-5"
commit-message:
prefix: "github-actions"
include: "scope"
- package-ecosystem: "maven"
directory: "/"
schedule:
interval: "daily"
pull-request-branch-name:
separator: "-"
reviewers:
- "openmrs/dev-5"
commit-message:
prefix: "maven"
include: "scope"
12 changes: 1 addition & 11 deletions api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -166,16 +166,6 @@
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-backward-codecs</artifactId>
</dependency>
<dependency>
<groupId>dom4j</groupId>
<artifactId>dom4j</artifactId>
<exclusions>
<exclusion>
<artifactId>xml-apis</artifactId>
<groupId>xml-apis</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
Expand Down Expand Up @@ -259,7 +249,7 @@
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>2.4.6</version>
<version>2.4.20</version>
<type>jar</type>
</dependency>
<dependency>
Expand Down
36 changes: 22 additions & 14 deletions api/src/main/java/org/openmrs/api/OrderSetService.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,9 @@ public interface OrderSetService extends OpenmrsService {
OrderSetMember getOrderSetMemberByUuid(String uuid);

/**
* @param uuid
* Get order set attribute by uuid
*
* @param uuid specifies the order set attribute uuid
* @return the {@link OrderSetAttribute} with the given uuid
* @since 2.4.0
* @should get the order set attribute with the given uuid
Expand All @@ -120,6 +122,8 @@ public interface OrderSetService extends OpenmrsService {
OrderSetAttribute getOrderSetAttributeByUuid(String uuid);

/**
* Get all order set attribute types
*
* @return all {@link OrderSetAttributeType}s
* @since 2.4.0
* @should return all orderSet attribute types including retired ones
Expand All @@ -128,7 +132,9 @@ public interface OrderSetService extends OpenmrsService {
List<OrderSetAttributeType> getAllOrderSetAttributeTypes();

/**
* @param id
* Get order set attribute type from the database by a given internal id
*
* @param id specifies the set attribute type id
* @return the {@link OrderSetAttributeType} with the given internal id
* @since 2.4.0
* @should return the orderSet attribute type with the given id
Expand All @@ -138,7 +144,9 @@ public interface OrderSetService extends OpenmrsService {
OrderSetAttributeType getOrderSetAttributeType(Integer id);

/**
* @param uuid
* Get order set attribute type by uuid
*
* @param uuid specifies the order set attribute type uuid
* @return the {@link OrderSetAttributeType} with the given uuid
* @since 2.4.0
* @should return the orderSet attribute type with the given uuid
Expand All @@ -148,9 +156,9 @@ public interface OrderSetService extends OpenmrsService {
OrderSetAttributeType getOrderSetAttributeTypeByUuid(String uuid);

/**
* Creates or updates the given orderSet attribute type in the database
* Creates or updates the given order set attribute type
*
* @param orderSetAttributeType
* @param orderSetAttributeType the order set attribute type to save
* @return the OrderSetAttributeType created/saved
* @since 2.4.0
* @should create a new orderSet attribute type
Expand All @@ -160,9 +168,9 @@ public interface OrderSetService extends OpenmrsService {
OrderSetAttributeType saveOrderSetAttributeType(OrderSetAttributeType orderSetAttributeType);

/**
* Retires the given orderSet attribute type in the database
* Retires the given order set attribute type
*
* @param orderSetAttributeType
* @param orderSetAttributeType specifies the order set attribute type to be retired
* @return the orderSetAttribute retired
* @since 2.4.0
* @should retire a orderSet attribute type
Expand All @@ -171,9 +179,9 @@ public interface OrderSetService extends OpenmrsService {
OrderSetAttributeType retireOrderSetAttributeType(OrderSetAttributeType orderSetAttributeType, String reason);

/**
* Restores a orderSet attribute type that was previous retired in the database
* Restores an order set attribute type that was previous retired
*
* @param orderSetAttributeType
* @param orderSetAttributeType the order set attribute type to be un-retired
* @return the OrderSetAttributeType unretired
* @since 2.4.0
* @should unretire a retired orderSet attribute type
Expand All @@ -182,19 +190,19 @@ public interface OrderSetService extends OpenmrsService {
OrderSetAttributeType unretireOrderSetAttributeType(OrderSetAttributeType orderSetAttributeType);

/**
* Completely removes a orderSet attribute type from the database
* Completely removes an order set attribute type
*
* @param orderSetAttributeType
* @param orderSetAttributeType the order set attribute type to be purged
* @since 2.4.0
* @should completely remove a orderSet attribute type
* @should completely remove an order set attribute type
*/
@Authorized(PrivilegeConstants.PURGE_ORDER_SET_ATTRIBUTE_TYPES)
void purgeOrderSetAttributeType(OrderSetAttributeType orderSetAttributeType);

/**
* Retrieves a OrderSetAttributeType object based on the name provided
* Retrieves an order set attribute type object based on the name provided
*
* @param orderSetAttributeTypeName
* @param orderSetAttributeTypeName fetches a given order set attribute type by name
* @return the {@link OrderSetAttributeType} with the specified name
* @since 2.4.0
* @should return the orderSet attribute type with the specified name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* <li>to decouple the org.openmrs.liquibase.ChangeLogDetective class from the
* org.openmrs.util.DatabaseUpdater class
* <li>to support integration testing of the org.openmrs.liquibase.ChangeLogDetective class with
* MariaDB
* the H2 database.
*
* @since 2.4
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
</generator>
</id>

<discriminator column="order_group_id" insert="false" />

<many-to-one name="orderSet" class="OrderSet">
<column name="order_set_id"/>
</many-to-one>
Expand Down
126 changes: 126 additions & 0 deletions api/src/test/java/org/openmrs/api/OrderSetServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertFalse;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
Expand All @@ -26,9 +27,11 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.openmrs.OrderSet;
import org.openmrs.OrderSetAttributeType;
import org.openmrs.OrderSetMember;
import org.openmrs.User;
import org.openmrs.api.context.Context;
import org.openmrs.customdatatype.datatype.FreeTextDatatype;
import org.openmrs.test.jupiter.BaseContextSensitiveTest;

public class OrderSetServiceTest extends BaseContextSensitiveTest {
Expand All @@ -41,6 +44,8 @@ public class OrderSetServiceTest extends BaseContextSensitiveTest {

protected static final String ORDER_SET = "org/openmrs/api/include/OrderSetServiceTest-general.xml";

protected static final String ORDER_SET_ATTRIBUTES = "org/openmrs/api/include/OrderSetServiceTest-attributes.xml";


/**
* Run this before each unit test in this class. The "@Before" method in
Expand Down Expand Up @@ -350,4 +355,125 @@ private OrderSet orderSetBuilder(boolean orderSetRetired, boolean orderSetMember
orderSet.setRetired(orderSetRetired);
return orderSet;
}


/**
* @see OrderSetService#getOrderSetAttributeByUuid(String)
*/
@Test
public void getOrderSetAttributeByUuid_shouldGetTheOrderSetAttributeWithTheGivenUuid() {
executeDataSet(ORDER_SET_ATTRIBUTES);
OrderSetService service = Context.getOrderSetService();
assertEquals("2011-04-25",service.getOrderSetAttributeByUuid("3a4bdb18-6faa-22e0-8414-001e376eb68e").getValueReference());
}

/**
* @see OrderSetService#getOrderSetAttributeByUuid(String)
*/
@Test
public void getOrderSetAttributeByUuid_shouldReturnNullIfNoOrderSetAttributeHasTheGivenUuid() {
executeDataSet(ORDER_SET_ATTRIBUTES);
OrderSetService service = Context.getOrderSetService();
assertNull(service.getOrderSetAttributeByUuid("not-a-uuid"));
}

/**
* @see OrderSetService#getOrderSetAttributeTypeByUuid(String)
*/
@Test
public void getOrderSetAttributeTypeByUuid_shouldReturnTheOrderSetAttributeTypeWithTheGivenUuid() {
executeDataSet(ORDER_SET_ATTRIBUTES);
assertEquals("Audit Date", Context.getOrderSetService().getOrderSetAttributeTypeByUuid(
"8516cc50-6f9f-33e0-8414-001e648eb67e").getName());
}

/**
* @see OrderSetService#getOrderSetAttributeTypeByUuid(String)
*/
@Test
public void getOrderSetAttributeTypeByUuid_shouldReturnNullIfNoOrderSetAttributeTypeExistsWithTheGivenUuid() {
executeDataSet(ORDER_SET_ATTRIBUTES);
assertNull(Context.getOrderSetService().getOrderSetAttributeTypeByUuid("not-a-uuid"));
}

/**
* @see OrderSetService#purgeOrderSetAttributeType(OrderSetAttributeType)
*/
@Test
public void purgeOrderSetAttributeType_shouldCompletelyRemoveAOrderSetAttributeType() {
executeDataSet(ORDER_SET_ATTRIBUTES);
int initialOrderSetAttributeTypesCount = Context.getOrderSetService().getAllOrderSetAttributeTypes().size();
Context.getOrderSetService().purgeOrderSetAttributeType(Context.getOrderSetService().getOrderSetAttributeType(2));
assertEquals(initialOrderSetAttributeTypesCount - 1, Context.getOrderSetService().getAllOrderSetAttributeTypes().size());
}

/**
* @see OrderSetService#retireOrderSetAttributeType(OrderSetAttributeType,String)
*/
@Test
public void retireOrderSetAttributeType_shouldRetireAOrderSetAttributeType() {
executeDataSet(ORDER_SET_ATTRIBUTES);
OrderSetAttributeType orderSetAttributeType = Context.getOrderSetService().getOrderSetAttributeType(1);
assertFalse(orderSetAttributeType.getRetired());
assertNull(orderSetAttributeType.getRetiredBy());
assertNull(orderSetAttributeType.getDateRetired());
assertNull(orderSetAttributeType.getRetireReason());
Context.getOrderSetService().retireOrderSetAttributeType(orderSetAttributeType, "for testing");
orderSetAttributeType = Context.getOrderSetService().getOrderSetAttributeType(1);
assertTrue(orderSetAttributeType.getRetired());
assertNotNull(orderSetAttributeType.getRetiredBy());
assertNotNull(orderSetAttributeType.getDateRetired());
assertEquals("for testing", orderSetAttributeType.getRetireReason());
}

/**
* @see OrderSetService#saveOrderSetAttributeType(OrderSetAttributeType)
*/
@Test
public void saveOrderSetAttributeType_shouldCreateANewOrderSetAttributeType() {
executeDataSet(ORDER_SET_ATTRIBUTES);
int initialOrderSetAttributeTypesCount = Context.getOrderSetService().getAllOrderSetAttributeTypes().size();
OrderSetAttributeType orderSetAttributeType = new OrderSetAttributeType();
orderSetAttributeType.setName("Another one");
orderSetAttributeType.setDatatypeClassname(FreeTextDatatype.class.getName());
Context.getOrderSetService().saveOrderSetAttributeType(orderSetAttributeType);
assertNotNull(orderSetAttributeType.getId());
assertEquals(initialOrderSetAttributeTypesCount + 1, Context.getOrderSetService().getAllOrderSetAttributeTypes().size());
}

/**
* @see OrderSetService#saveOrderSetAttributeType(OrderSetAttributeType)
*/
@Test
public void saveOrderSetAttributeType_shouldEditAnExistingOrderSetAttributeType() {
executeDataSet(ORDER_SET_ATTRIBUTES);
int initialOrderSetAttributeTypesCount = Context.getOrderSetService().getAllOrderSetAttributeTypes().size();
OrderSetService service = Context.getOrderSetService();
OrderSetAttributeType orderSetAttributeType = service.getOrderSetAttributeType(1);
orderSetAttributeType.setName("A new name");
service.saveOrderSetAttributeType(orderSetAttributeType);
assertEquals(initialOrderSetAttributeTypesCount, service.getAllOrderSetAttributeTypes().size());
assertEquals("A new name", service.getOrderSetAttributeType(1).getName());
}

/**
* @see OrderSetService#unretireOrderSetAttributeType(OrderSetAttributeType)
*/
@Test
public void unretireOrderSetAttributeType_shouldUnretireARetiredOrderSetAttributeType() {
executeDataSet(ORDER_SET_ATTRIBUTES);
OrderSetService service = Context.getOrderSetService();
OrderSetAttributeType orderSetAttributeType = service.getOrderSetAttributeType(2);
assertTrue(orderSetAttributeType.getRetired());
assertNotNull(orderSetAttributeType.getDateRetired());
assertNotNull(orderSetAttributeType.getRetiredBy());
assertNotNull(orderSetAttributeType.getRetireReason());
service.unretireOrderSetAttributeType(orderSetAttributeType);
assertFalse(orderSetAttributeType.getRetired());
assertNull(orderSetAttributeType.getDateRetired());
assertNull(orderSetAttributeType.getRetiredBy());
assertNull(orderSetAttributeType.getRetireReason());
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
This Source Code Form is subject to the terms of the Mozilla Public License,
v. 2.0. If a copy of the MPL was not distributed with this file, You can
obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under
the terms of the Healthcare Disclaimer located at http://openmrs.org/license.
Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS
graphic logo is a trademark of OpenMRS Inc.
-->

<dataset>
<order_set order_set_id="1" name="Order_Set_1" description="Order_Set_1_desc" operator="ALL" creator="1" date_created="2008-08-15 15:49:04.0" retired="0" uuid="2d3fb1d0-ae06-22e3-a5e2-0140211c1001" />
<order_set_attribute_type order_set_attribute_type_id="1" name="Audit Date" datatype="org.openmrs.customdatatype.datatype.DateDatatype" uuid="8516cc50-6f9f-33e0-8414-001e648eb67e" creator="1" date_created="2005-01-01 00:00:00.0" min_occurs="0" retired="false" />
<order_set_attribute_type order_set_attribute_type_id="2" name="A Date We Don't Care About" datatype="org.openmrs.customdatatype.datatype.DateDatatype" uuid="9545cc50-6f9f-55e0-8414-001e378eb69f" creator="1" date_created="2005-01-01 00:00:00.0" min_occurs="0" retired="true" retired_by="1" date_retired="2005-01-01 02:00:00.0" retire_reason="for fun and profit" />
<order_set_attribute order_set_attribute_id="1" order_set_id="1" attribute_type_id="1" value_reference="2011-04-25" uuid="3a4bdb18-6faa-22e0-8414-001e376eb68e" creator="1" date_created="2005-01-01 00:00:00.0" voided="false" />
</dataset>
Binary file not shown.
Binary file not shown.
8 changes: 4 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.4</version>
<version>3.1.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand Down Expand Up @@ -813,7 +813,7 @@
<plugin>
<groupId>org.eluder.coveralls</groupId>
<artifactId>coveralls-maven-plugin</artifactId>
<version>4.2.0</version>
<version>4.3.0</version>
</plugin>
<plugin>
<groupId>com.mycila</groupId>
Expand Down Expand Up @@ -895,7 +895,7 @@
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2-beta-5</version>
<version>3.3.0</version>
<configuration>
<descriptorRefs>
<descriptorRef>project</descriptorRef>
Expand Down Expand Up @@ -1106,7 +1106,7 @@
<openmrs.version.shortnumericonly>${parsedVersion.majorVersion}.${parsedVersion.minorVersion}.${parsedVersion.incrementalVersion}</openmrs.version.shortnumericonly>
<openmrs.version>${project.version}</openmrs.version>

<springVersion>5.2.7.RELEASE</springVersion>
<springVersion>5.2.8.RELEASE</springVersion>
<hibernateVersion>5.4.18.Final</hibernateVersion>
<slf4jVersion> 1.7.30</slf4jVersion>
<log4jVersion>2.13.3</log4jVersion>
Expand Down

0 comments on commit f21c16b

Please sign in to comment.