Skip to content

Commit

Permalink
Added tests for the running application and bug fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
volsch committed Nov 22, 2018
1 parent e4f01f9 commit 116a4a3
Show file tree
Hide file tree
Showing 54 changed files with 21,904 additions and 99 deletions.
16 changes: 16 additions & 0 deletions app/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,22 @@
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.github.tomakehurst</groupId>
<artifactId>wiremock</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
4 changes: 3 additions & 1 deletion app/src/main/java/org/dhis2/fhir/adapter/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ public class App extends SpringBootServletInitializer

public static final String DHIS2_HOME_PROP = "dhis2.home";

public static final String RELATIVE_APPLICATION_PROPERTY_SOURCE = "services/fhir-adapter/application.yml";

@Override
protected SpringApplicationBuilder configure( SpringApplicationBuilder application )
{
Expand Down Expand Up @@ -94,7 +96,7 @@ protected static void checkEnv() throws AppException
throw new AppException( "DHIS2 home environment variable " + DHIS2_HOME_ENV + " has not been set." );
}

final File configFile = new File( home + "/services/fhir-adapter/application.yml" );
final File configFile = new File( home + "/" + RELATIVE_APPLICATION_PROPERTY_SOURCE );
if ( !configFile.canRead() )
{
throw new AppException( "Adapter configuration file does not exist or cannot be read: " + configFile.getAbsolutePath() );
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/java/org/dhis2/fhir/adapter/AppException.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,9 @@ public AppException( String message )
{
super( message );
}

public AppException( String message, Throwable cause )
{
super( message, cause );
}
}
67 changes: 67 additions & 0 deletions app/src/main/java/org/dhis2/fhir/adapter/setup/SetupResult.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package org.dhis2.fhir.adapter.setup;

/*
* Copyright (c) 2004-2018, University of Oslo
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* Neither the name of the HISP project nor the names of its contributors may
* be used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

import org.dhis2.fhir.adapter.fhir.metadata.model.FhirResourceType;

import javax.annotation.Nonnull;
import java.io.Serializable;
import java.util.Collections;
import java.util.Map;
import java.util.UUID;

/**
* The result of the setup of the FHIR adapter.
*/
public class SetupResult implements Serializable
{
private static final long serialVersionUID = -5493649240520618453L;

private final UUID remoteSubscriptionId;

private final Map<FhirResourceType, UUID> remoteSubscriptionResourceIds;

public SetupResult( @Nonnull UUID remoteSubscriptionId, @Nonnull Map<FhirResourceType, UUID> remoteSubscriptionResourceIds )
{
this.remoteSubscriptionId = remoteSubscriptionId;
this.remoteSubscriptionResourceIds = Collections.unmodifiableMap( remoteSubscriptionResourceIds );
}

@Nonnull
public UUID getRemoteSubscriptionId()
{
return remoteSubscriptionId;
}

@Nonnull
public Map<FhirResourceType, UUID> getRemoteSubscriptionResourceIds()
{
return remoteSubscriptionResourceIds;
}
}
10 changes: 7 additions & 3 deletions app/src/main/java/org/dhis2/fhir/adapter/setup/SetupService.java
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public boolean hasCompletedSetup()
}

@Transactional
public void apply( @Nonnull Setup setup )
public SetupResult apply( @Nonnull Setup setup )
{
final System organizationSystem = findOrCreateSystem(
setup.getRemoteSubscriptionSetup().getSystemUriSetup().getOrganizationSystemUri(),
Expand All @@ -145,12 +145,14 @@ public void apply( @Nonnull Setup setup )
setup.getRemoteSubscriptionSetup().getSystemUriSetup().getPatientSystemUri(),
"Default DHIS2 Patients", "DEFAULT_DHIS2_PATIENT", "Default DHIS2 patient system URI." );

createRemoteSubscription( setup.getRemoteSubscriptionSetup(), organizationSystem, patientSystem );
final SetupResult setupResult = createRemoteSubscription( setup.getRemoteSubscriptionSetup(), organizationSystem, patientSystem );
createSystemCodes( setup.getOrganizationCodeSetup(), organizationSystem );
updateTrackedEntity( setup.getTrackedEntitySetup() );
return setupResult;
}

private void createRemoteSubscription( @Nonnull RemoteSubscriptionSetup setup, @Nonnull System organizationSystem, @Nonnull System patientSystem )
@Nonnull
private SetupResult createRemoteSubscription( @Nonnull RemoteSubscriptionSetup setup, @Nonnull System organizationSystem, @Nonnull System patientSystem )
{
final Set<FhirResourceType> autoCreatedSubscriptionResources = new HashSet<>();
autoCreatedSubscriptionResources.add( FhirResourceType.PATIENT );
Expand Down Expand Up @@ -223,6 +225,8 @@ private void createRemoteSubscription( @Nonnull RemoteSubscriptionSetup setup, @
remoteSubscription.getSystems().add( subscriptionPatientSystem );

remoteSubscriptionRepository.saveAndFlush( remoteSubscription );
return new SetupResult( remoteSubscription.getId(), remoteSubscription.getResources().stream()
.collect( Collectors.toMap( RemoteSubscriptionResource::getFhirResourceType, rsr -> rsr.getId() ) ) );
}

private void createSystemCodes( @Nonnull OrganizationCodeSetup setup, @Nonnull System organizationSystem )
Expand Down
1 change: 1 addition & 0 deletions app/src/main/resources/logback-spring.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@

<logger name="org.hibernate" level="warn" />
<logger name="org.hibernate.cfg.AnnotationBinder" level="error" />
<logger name="org.hibernate.engine.jdbc.spi.SqlExceptionHelper" level="off" />
<logger name="org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver" level="error" />
<logger name="org.springframework.data.repository.config.RepositoryConfigurationDelegate" level="warn" />
<logger name="org.springframework.data.repository.config.RepositoryConfigurationExtensionSupport" level="warn" />
Expand Down
Loading

0 comments on commit 116a4a3

Please sign in to comment.