-
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
154 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
src/main/java/org/commonwl/view/util/JpaConverterJson.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package org.commonwl.view.util; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
|
||
import javax.persistence.AttributeConverter; | ||
import javax.persistence.Converter; | ||
|
||
/** | ||
* @see <a href="https://stackoverflow.com/questions/25738569/how-to-map-a-map-json-column-to-java-object-with-jpa">https://stackoverflow.com/questions/25738569/how-to-map-a-map-json-column-to-java-object-with-jpa</a> | ||
*/ | ||
@Converter(autoApply = true) | ||
public class JpaConverterJson implements AttributeConverter<Object, String> { | ||
|
||
private static final ObjectMapper objectMapper = new ObjectMapper(); | ||
|
||
@Override | ||
public String convertToDatabaseColumn(Object meta) { | ||
try { | ||
return objectMapper.writeValueAsString(meta); | ||
} catch (JsonProcessingException ex) { | ||
return null; | ||
} | ||
} | ||
|
||
@Override | ||
public Object convertToEntityAttribute(String dbData) { | ||
try { | ||
return objectMapper.readValue(dbData, Object.class); | ||
} catch (JsonProcessingException ex) { | ||
return null; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
src/test/java/org/commonwl/view/workflow/PostgreSQLContextInitializer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package org.commonwl.view.workflow; | ||
|
||
import org.springframework.boot.test.util.TestPropertyValues; | ||
import org.springframework.context.ApplicationContextInitializer; | ||
import org.springframework.context.ApplicationEvent; | ||
import org.springframework.context.ApplicationListener; | ||
import org.springframework.context.ConfigurableApplicationContext; | ||
import org.springframework.context.event.ContextClosedEvent; | ||
import org.testcontainers.containers.PostgreSQLContainer; | ||
|
||
/** | ||
* A test application context initializer that creates the database Docker container used for functional tests. | ||
*/ | ||
public class PostgreSQLContextInitializer implements ApplicationContextInitializer<ConfigurableApplicationContext> { | ||
|
||
@Override | ||
public void initialize(ConfigurableApplicationContext applicationContext) { | ||
PostgreSQLContainer<?> postgreSQLContainer = new PostgreSQLContainer<>("postgres:9.6.12") | ||
.withDatabaseName("cwlviewer") | ||
.withUsername("sa") | ||
.withPassword("sa"); | ||
postgreSQLContainer.start(); | ||
TestPropertyValues.of("spring.datasource.url=" + postgreSQLContainer.getJdbcUrl(), | ||
"spring.datasource.username=" + postgreSQLContainer.getUsername(), | ||
"spring.datasource.password=" + postgreSQLContainer.getPassword(), | ||
"spring.jpa.hibernate.ddl-auto=create") | ||
.applyTo(applicationContext.getEnvironment()); | ||
applicationContext.addApplicationListener(new ApplicationListener<ContextClosedEvent>() { | ||
@Override | ||
public void onApplicationEvent(ContextClosedEvent event) { | ||
postgreSQLContainer.stop(); | ||
} | ||
}); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters