Skip to main content
summaryrefslogtreecommitdiffstats
blob: fe0760d8cef42153633cb30086f26534400f6f36 (plain) (blame)
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
/*******************************************************************************
 * Copyright (c) 2004, 2007 Boeing.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Boeing - initial API and implementation
 *******************************************************************************/
package org.eclipse.osee.orcs.db.intergration;

import static org.eclipse.osee.orcs.db.intergration.IntegrationUtil.integrationRule;
import java.sql.DatabaseMetaData;
import org.eclipse.osee.framework.jdk.core.type.OseeCoreException;
import org.eclipse.osee.framework.jdk.core.type.OseeStateException;
import org.eclipse.osee.jdbc.JdbcConnection;
import org.eclipse.osee.jdbc.JdbcDbType;
import org.eclipse.osee.jdbc.JdbcService;
import org.eclipse.osee.orcs.core.ds.DataStoreConstants;
import org.eclipse.osee.orcs.db.internal.SqlProvider;
import org.eclipse.osee.orcs.db.internal.accessor.OseeInfoDataAccessor;
import org.eclipse.osee.orcs.db.internal.resource.ResourceConstants;
import org.eclipse.osee.orcs.db.mock.OsgiService;
import org.eclipse.osee.orcs.db.mocks.MockLog;
import org.junit.Assert;
import org.junit.Rule;
import org.junit.rules.TestRule;

/**
 * Test Case for {@link OseeInfoDataAccessor}
 * 
 * @author Roberto E. Escobar
 */
public class OseeInfoDataAccessorTest {

   @Rule
   public TestRule db = integrationRule(this);

   //@formatter:off
   @OsgiService private JdbcService jdbcService;
   //@formatter:on

   @org.junit.Test
   public void testGetSetValue() throws OseeCoreException {
      OseeInfoDataAccessor accessor = new OseeInfoDataAccessor();
      accessor.setLogger(new MockLog());
      accessor.setJdbcService(jdbcService);

      String value = accessor.getValue("test.data");
      Assert.assertEquals("", value);

      boolean wasSuccessful = accessor.putValue("test.data", "testing 1,2,3");
      Assert.assertTrue(wasSuccessful);

      String value1 = accessor.getValue("test.data");
      Assert.assertEquals("testing 1,2,3", value1);
   }

   @org.junit.Test(expected = OseeStateException.class)
   public void testSetBinaryDataPath() throws OseeCoreException {
      OseeInfoDataAccessor accessor = new OseeInfoDataAccessor();
      accessor.setLogger(new MockLog());
      accessor.setJdbcService(jdbcService);

      accessor.putValue(ResourceConstants.BINARY_DATA_PATH, "dummy");
   }

   @org.junit.Test
   public void testGetBinaryDataPath() throws OseeCoreException {
      OseeInfoDataAccessor accessor = new OseeInfoDataAccessor();
      accessor.setLogger(new MockLog());
      accessor.setJdbcService(jdbcService);

      String original = accessor.getValue(ResourceConstants.BINARY_DATA_PATH);
      Assert.assertEquals(System.getProperty(ResourceConstants.BINARY_DATA_PATH), original);

      System.setProperty(ResourceConstants.BINARY_DATA_PATH, "");
      try {
         String actual = accessor.getValue(ResourceConstants.BINARY_DATA_PATH);
         Assert.assertEquals(System.getProperty("user.home"), actual);
      } finally {
         System.setProperty(ResourceConstants.BINARY_DATA_PATH, original);
      }
   }

   @org.junit.Test(expected = OseeStateException.class)
   public void testSetDatabaseHintsSupported() throws OseeCoreException {
      OseeInfoDataAccessor accessor = new OseeInfoDataAccessor();
      accessor.setLogger(new MockLog());
      accessor.setJdbcService(jdbcService);

      accessor.putValue(SqlProvider.SQL_DATABASE_HINTS_SUPPORTED_KEY, "dummy");
   }

   @org.junit.Test
   public void testGetDatabaseHintsSupported() throws OseeCoreException {
      OseeInfoDataAccessor accessor = new OseeInfoDataAccessor();
      accessor.setLogger(new MockLog());
      accessor.setJdbcService(jdbcService);

      String original = accessor.getValue(SqlProvider.SQL_DATABASE_HINTS_SUPPORTED_KEY);

      boolean expected = false;
      JdbcConnection connection = jdbcService.getClient().getConnection();
      try {
         DatabaseMetaData metaData = connection.getMetaData();
         expected = JdbcDbType.isDatabaseType(metaData, JdbcDbType.oracle);
      } finally {
         connection.close();
      }
      Assert.assertEquals(expected, Boolean.parseBoolean(original));
   }

   @org.junit.Test(expected = OseeStateException.class)
   public void testSetSQLRecursiveKeyword() throws OseeCoreException {
      OseeInfoDataAccessor accessor = new OseeInfoDataAccessor();
      accessor.setLogger(new MockLog());
      accessor.setJdbcService(jdbcService);

      accessor.putValue(SqlProvider.SQL_RECURSIVE_WITH_KEY, "dummy");
   }

   @org.junit.Test
   public void testGetSQLRecursiveKeyword() throws OseeCoreException {
      OseeInfoDataAccessor accessor = new OseeInfoDataAccessor();
      accessor.setLogger(new MockLog());
      accessor.setJdbcService(jdbcService);

      String original = accessor.getValue(SqlProvider.SQL_RECURSIVE_WITH_KEY);

      String expected = "";
      JdbcConnection connection = jdbcService.getClient().getConnection();
      try {
         DatabaseMetaData metaData = connection.getMetaData();
         if (!JdbcDbType.isDatabaseType(metaData, JdbcDbType.oracle)) {
            expected = "RECURSIVE";
         }
      } finally {
         connection.close();
      }
      Assert.assertEquals(expected, original);
   }

   @org.junit.Test(expected = OseeStateException.class)
   public void testSetSQLRegExpPattern() throws OseeCoreException {
      OseeInfoDataAccessor accessor = new OseeInfoDataAccessor();
      accessor.setLogger(new MockLog());
      accessor.setJdbcService(jdbcService);

      accessor.putValue(SqlProvider.SQL_REG_EXP_PATTERN_KEY, "dummy");
   }

   @org.junit.Test
   public void testGetSQLRegExpPattern() throws OseeCoreException {
      OseeInfoDataAccessor accessor = new OseeInfoDataAccessor();
      accessor.setLogger(new MockLog());
      accessor.setJdbcService(jdbcService);

      String original = accessor.getValue(SqlProvider.SQL_REG_EXP_PATTERN_KEY);

      String expected = "";
      JdbcConnection connection = jdbcService.getClient().getConnection();
      try {
         DatabaseMetaData metaData = connection.getMetaData();
         JdbcDbType db = JdbcDbType.getDatabaseType(metaData);
         if (JdbcDbType.oracle == db) {
            expected = "REGEXP_LIKE (%s, %s)";
         } else if (JdbcDbType.hsql == db || JdbcDbType.postgresql == db) {
            expected = "REGEXP_MATCHES (%s, %s)";
         } else if (JdbcDbType.mysql == db) {
            expected = "(%s REGEXP %s)";
         }
      } finally {
         connection.close();
      }
      Assert.assertEquals(expected, original);
   }

   @org.junit.Test(expected = OseeStateException.class)
   public void testSetCheckTagQueueOnStartupAllowed() throws OseeCoreException {
      OseeInfoDataAccessor accessor = new OseeInfoDataAccessor();
      accessor.setLogger(new MockLog());
      accessor.setJdbcService(jdbcService);

      accessor.putValue(DataStoreConstants.DATASTORE_INDEX_ON_START_UP, "dummy");
   }

   @org.junit.Test
   public void testGetCheckTagQueueOnStartupAllowed() throws OseeCoreException {
      OseeInfoDataAccessor accessor = new OseeInfoDataAccessor();
      accessor.setLogger(new MockLog());
      accessor.setJdbcService(jdbcService);

      String original = accessor.getValue(DataStoreConstants.DATASTORE_INDEX_ON_START_UP);
      Assert.assertEquals(System.getProperty(DataStoreConstants.DATASTORE_INDEX_ON_START_UP, "false"), original);

      System.setProperty(DataStoreConstants.DATASTORE_INDEX_ON_START_UP, "true");
      try {
         String actual = accessor.getValue(DataStoreConstants.DATASTORE_INDEX_ON_START_UP);
         Assert.assertEquals("true", actual);
      } finally {
         System.setProperty(DataStoreConstants.DATASTORE_INDEX_ON_START_UP, original);
      }
   }

   @org.junit.Test
   public void testGetKeys() throws OseeCoreException {
      OseeInfoDataAccessor accessor = new OseeInfoDataAccessor();
      accessor.setLogger(new MockLog());
      accessor.setJdbcService(jdbcService);
      Assert.assertTrue(!accessor.getKeys().isEmpty());
   }

}

Back to the top