2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 - 2018 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
23 import org.junit.Assert;
24 import org.junit.Before;
25 import org.junit.Test;
26 import org.onap.so.adapters.vnf.BaseRestTestUtils;
27 import org.springframework.beans.factory.annotation.Autowired;
28 import org.springframework.beans.factory.annotation.Qualifier;
30 import javax.sql.DataSource;
31 import java.sql.Connection;
32 import java.sql.ResultSet;
33 import java.sql.Statement;
35 public class CloudConfigMigrationTest extends BaseRestTestUtils {
37 @Qualifier("dataSource")
39 DataSource dataSource;
41 R__CloudConfigMigration cloudConfigMigration;
45 cloudConfigMigration = new R__CloudConfigMigration();
49 public void testMigrate() throws Exception {
50 System.setProperty("spring.profiles.active", "test");
51 cloudConfigMigration.migrate(dataSource.getConnection());
52 assertMigratedIdentityServiceData();
53 assertMigratedCloudSiteData();
54 assertMigratedCloudManagerData();
58 public void testMigrateNoData() throws Exception {
59 System.setProperty("spring.profiles.active", "nomigrate");
60 int identityCount = getDataCount("identity_services");
61 int cloudSiteCount = getDataCount("cloud_sites");
62 int cloudManagerCount = getDataCount("cloudify_managers");
64 cloudConfigMigration.migrate(dataSource.getConnection());
66 Assert.assertEquals(identityCount, getDataCount("identity_services"));
67 Assert.assertEquals(cloudSiteCount, getDataCount("cloud_sites"));
68 Assert.assertEquals(cloudManagerCount, getDataCount("cloudify_managers"));
72 private int getDataCount(String tableName) throws Exception {
73 try (Connection con = dataSource.getConnection(); Statement stmt = con.createStatement(); ResultSet rs = stmt.executeQuery("select count(1) from " + tableName)) {
81 private void assertMigratedIdentityServiceData() throws Exception {
82 try (Connection con = dataSource.getConnection(); Statement stmt = con.createStatement(); ResultSet rs = stmt.executeQuery("select * from identity_services where id='MTKEYSTONE'")) {
83 boolean dataAvailable = false;
86 Assert.assertEquals("MTKEYSTONE", rs.getString("id"));
87 Assert.assertEquals("http://localhost:5000/v2.0", rs.getString("identity_url"));
88 Assert.assertEquals("john", rs.getString("mso_id"));
89 Assert.assertEquals("313DECE408AF7759D442D7B06DD9A6AA", rs.getString("mso_pass"));
90 Assert.assertEquals("admin", rs.getString("admin_tenant"));
91 Assert.assertEquals("_member_", rs.getString("member_role"));
92 Assert.assertEquals("KEYSTONE", rs.getString("identity_server_type"));
93 Assert.assertEquals("USERNAME_PASSWORD", rs.getString("identity_authentication_type"));
95 Assert.assertTrue("Expected data in identity_services table post migration but didnt find any!!!", dataAvailable);
99 private void assertMigratedCloudSiteData() throws Exception {
100 try (Connection con = dataSource.getConnection(); Statement stmt = con.createStatement(); ResultSet rs = stmt.executeQuery("select * from cloud_sites where id='regionOne'")) {
101 boolean dataAvailable = false;
103 dataAvailable = true;
104 Assert.assertEquals("regionOne", rs.getString("id"));
105 Assert.assertEquals("regionOne", rs.getString("region_id"));
106 Assert.assertEquals("MT2", rs.getString("clli"));
107 Assert.assertEquals("2.5", rs.getString("cloud_version"));
108 Assert.assertEquals("MTKEYSTONE", rs.getString("identity_service_id"));
110 Assert.assertTrue("Expected data in identity_services table post migration but didnt find any!!!", dataAvailable);
114 private void assertMigratedCloudManagerData() throws Exception {
115 try (Connection con = dataSource.getConnection(); Statement stmt = con.createStatement(); ResultSet rs = stmt.executeQuery("select * from cloudify_managers where id='manager'")) {
116 boolean dataAvailable = false;
118 dataAvailable = true;
119 Assert.assertEquals("http://localhost:8080", rs.getString("cloudify_url"));
120 Assert.assertEquals("user", rs.getString("username"));
121 Assert.assertEquals("password", rs.getString("password"));
122 Assert.assertEquals("2.0", rs.getString("version"));
124 Assert.assertTrue("Expected data in identity_services table post migration but didnt find any!!!", dataAvailable);