aboutsummaryrefslogtreecommitdiffstats
path: root/mso-catalog-db/pom.xml
blob: ff88b8146159f18e7f4c78c191761ee3d25b562f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <groupId>org.onap.so</groupId>
    <artifactId>so</artifactId>
    <version>1.7.1-SNAPSHOT</version>
  </parent>

  <artifactId>mso-catalog-db</artifactId>
  <name>mso-catalog-db</name>
  <description>MSO Catalog Database definition and Hibernate objects</description>

  <build>
    <finalName>${project.artifactId}</finalName>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jar-plugin</artifactId>
        <executions>
          <execution>
            <phase>package</phase>
            <goals>
              <goal>jar</goal>
            </goals>
            <configuration>
              <classifier>beans</classifier>
              <includes>
                <include>**/beans/*</include>
                <include>**/macro/*</include>
                <include>**/utils/*</include>
              </includes>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
  <dependencies>
    <dependency>
      <groupId>uk.co.blackpepper.bowman</groupId>
      <artifactId>bowman-client</artifactId>
      <version>${bowman.client.version}</version>
    </dependency>
    <dependency>
      <groupId>org.onap.so</groupId>
      <artifactId>common</artifactId>
      <version>${project.version}</version>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-data-jpa</artifactId>
      <optional>true</optional>
    </dependency>
    <dependency>
      <groupId>org.mariadb.jdbc</groupId>
      <artifactId>mariadb-java-client</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-test</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>ch.vorburger.mariaDB4j</groupId>
      <artifactId>mariaDB4j</artifactId>
      <version>2.2.3</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-data-rest</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework.data</groupId>
      <artifactId>spring-data-rest-hal-browser</artifactId>
    </dependency>
    <dependency>
      <groupId>org.ow2.asm</groupId>
      <artifactId>asm-xml</artifactId>
      <version>6.1</version>
    </dependency>
    <dependency>
      <groupId>org.glassfish.jersey.core</groupId>
      <artifactId>jersey-common</artifactId>
      <scope>test</scope>
    </dependency>
  </dependencies>
</project>
="cm"> */ public class PolicyLegacyOperationalPersistenceTest { private StandardCoder standardCoder; private PolicyModelsProvider databaseProvider; // @formatter:off private String[] policyInputResourceNames = { "policies/vCPE.policy.operational.input.json", "policies/vDNS.policy.operational.input.json", "policies/vFirewall.policy.operational.input.json" }; private String[] policyOutputResourceNames = { "policies/vCPE.policy.operational.output.json", "policies/vDNS.policy.operational.output.json", "policies/vFirewall.policy.operational.output.json" }; // @formatter:on /** * Initialize provider. * * @throws PfModelException on exceptions in the tests * @throws CoderException on JSON encoding and decoding errors */ @Before public void setupParameters() throws Exception { // H2, use "org.mariadb.jdbc.Driver" and "jdbc:mariadb://localhost:3306/policy" for locally installed MariaDB PolicyModelsProviderParameters parameters = new PolicyModelsProviderParameters(); parameters.setDatabaseDriver("org.h2.Driver"); parameters.setDatabaseUrl("jdbc:h2:mem:testdb"); parameters.setDatabaseUser("policy"); parameters.setDatabasePassword(Base64.getEncoder().encodeToString("P01icY".getBytes())); parameters.setPersistenceUnit("ToscaConceptTest"); databaseProvider = new PolicyModelsProviderFactory().createPolicyModelsProvider(parameters); createPolicyTypes(); } /** * Set up standard coder. */ @Before public void setupStandardCoder() { standardCoder = new StandardCoder(); } @After public void teardown() throws Exception { databaseProvider.close(); } @Test public void testLegacyOperationalPolicyPersistence() throws Exception { for (int i = 0; i < policyInputResourceNames.length; i++) { String policyInputString = ResourceUtils.getResourceAsString(policyInputResourceNames[i]); String policyOutputString = ResourceUtils.getResourceAsString(policyOutputResourceNames[i]); testJsonStringPolicyPersistence(policyInputString, policyOutputString); } } /** * Check persistence of a policy. * * @param policyInputString the policy as a string * @param policyOutputString the expected output string * @throws Exception any exception thrown */ public void testJsonStringPolicyPersistence(@NonNull final String policyInputString, final String policyOutputString) throws Exception { LegacyOperationalPolicy lop = standardCoder.decode(policyInputString, LegacyOperationalPolicy.class); assertNotNull(lop); LegacyOperationalPolicy createdLop = databaseProvider.createOperationalPolicy(lop); assertEquals(createdLop, lop); LegacyOperationalPolicy gotLop = databaseProvider.getOperationalPolicy(lop.getPolicyId(), null); assertEquals(gotLop, lop); LegacyOperationalPolicy updatedLop = databaseProvider.updateOperationalPolicy(lop); assertEquals(gotLop, updatedLop); LegacyOperationalPolicy deletedLop = databaseProvider.deleteOperationalPolicy(lop.getPolicyId(), "1"); assertEquals(gotLop, deletedLop); String actualRetrievedJson = standardCoder.encode(gotLop); // All of this dash/underscore stuff is to avoid a checkstyle error around escaping unicode characters assertEquals( policyOutputString.replaceAll("\\s+", "").replaceAll("u0027", "_-_-_-_").replaceAll("\\\\_-_-_-_", "'"), actualRetrievedJson.replaceAll("\\s+", "").replaceAll("u0027", "_-_-_-_").replaceAll("\\\\_-_-_-_", "'")); } private void createPolicyTypes() throws CoderException, PfModelException, URISyntaxException { Set<String> policyTypeResources = ResourceUtils.getDirectoryContents("policytypes"); for (String policyTypeResource : policyTypeResources) { Object yamlObject = new Yaml().load(ResourceUtils.getResourceAsString(policyTypeResource)); String yamlAsJsonString = new StandardCoder().encode(yamlObject); ToscaServiceTemplate toscaServiceTemplatePolicyType = standardCoder.decode(yamlAsJsonString, ToscaServiceTemplate.class); assertNotNull(toscaServiceTemplatePolicyType); databaseProvider.createPolicyTypes(toscaServiceTemplatePolicyType); } } }