aboutsummaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib/openecomp-core-lib/openecomp-config-lib/src/test/java/org/openecomp/sdc/applicationconfig/dao/ApplicationConfigImplDaoTest.java
blob: 40cde1ecb2ed9b482a68dfcb2097226580ec3241 (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
package org.openecomp.sdc.applicationconfig.dao;

import org.openecomp.sdc.common.errors.CoreException;
import org.openecomp.sdc.common.errors.ErrorCategory;
import org.openecomp.sdc.common.errors.ErrorCode;
import org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionEntityType;
import org.openecomp.core.utilities.applicationconfig.ApplicationConfig;
import org.openecomp.core.utilities.applicationconfig.ApplicationConfigFactory;
import org.openecomp.core.utilities.applicationconfig.dao.ApplicationConfigDao;
import org.openecomp.core.utilities.applicationconfig.dao.ApplicationConfigDaoFactory;
import org.openecomp.core.utilities.applicationconfig.dao.type.ApplicationConfigEntity;
import org.openecomp.core.utilities.applicationconfig.type.ConfigurationData;
import org.openecomp.core.utilities.file.FileUtils;
import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;


public class ApplicationConfigImplDaoTest {

  private static final String SCHEMA_GENERATOR_INITIALIZATION_ERROR =
      "SCHEMA_GENERATOR_INITIALIZATION_ERROR";
  private static final String SCHEMA_GENERATOR_INITIALIZATION_ERROR_MSG =
      "Error occurred while loading questionnaire schema templates";
  private static ApplicationConfigDao applicationConfigDao =
      ApplicationConfigDaoFactory.getInstance().createInterface();
  private static ApplicationConfig applicationConfig =
      ApplicationConfigFactory.getInstance().createInterface();

//  @BeforeClass
  public static void init() {
    try {

      ApplicationConfigEntity applicationConfigEntity1 =
          new ApplicationConfigEntity("test - namespace", "vsp", "vspTemplate");
      ApplicationConfigEntity applicationConfigEntity2 =
          new ApplicationConfigEntity("test - namespace", "nic", "nicTemplate");
      ApplicationConfigEntity applicationConfigEntity3 =
          new ApplicationConfigEntity("test - namespace", "component", "componentTemplate");

      applicationConfigDao.create(applicationConfigEntity1);
      applicationConfigDao.create(applicationConfigEntity2);
      applicationConfigDao.create(applicationConfigEntity3);

    } catch (Exception e) {
      throw new CoreException(new ErrorCode.ErrorCodeBuilder().
          withCategory(ErrorCategory.APPLICATION).
          withId(SCHEMA_GENERATOR_INITIALIZATION_ERROR).
          withMessage(SCHEMA_GENERATOR_INITIALIZATION_ERROR_MSG).
          build());
    }
  }

  private static String loadFileToString(String path) {
    return new String(FileUtils.toByteArray(FileUtils.loadFileToInputStream(path)));
  }

//  @Test
  public void testApplicationConfigTimestampValue() {
    ConfigurationData configurationData = applicationConfig
        .getConfigurationData("test - namespace", CompositionEntityType.vsp.name());

    Assert.assertNotNull(configurationData);
    Assert.assertNotEquals(configurationData.getTimeStamp(), 0);

  }

//  @Test(dependsOnMethods = "testApplicationConfigTimestampValue")
  public void testNotExistingApplicationConfigTimestampValue() {
    try {
      applicationConfig.getConfigurationData("test - namespace", "aaa");
    } catch (CoreException ce) {
      Assert.assertEquals(ce.getMessage(),
          "Configuration for namespace test - namespace and key aaa was not found");
    }

  }

//  @Test(dependsOnMethods = "testApplicationConfigTimestampValue")
  public void testInsertApplicationConfiguration() {
    String testTemplate = loadFileToString("questionnaire/testTemplate.txt");
    applicationConfig.insertValue("test_namespace", "test_key", testTemplate);

    Assert.assertEquals(testTemplate,
        applicationConfig.getConfigurationData("test_namespace", "test_key").getValue());
  }

}