* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- *
+ *
* SPDX-License-Identifier: Apache-2.0
* ============LICENSE_END=========================================================
*/
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
-import org.onap.policy.apex.context.test.entities.ArtifactKeyTestEntity;
-import org.onap.policy.apex.context.test.entities.ReferenceKeyTestEntity;
import org.onap.policy.apex.model.basicmodel.concepts.ApexException;
import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
import org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey;
-import org.onap.policy.apex.model.basicmodel.dao.DAOParameters;
+import org.onap.policy.apex.model.basicmodel.dao.DaoParameters;
+import org.onap.policy.apex.plugins.persistence.jpa.eclipselink.entities.ArtifactKeyTestEntity;
+import org.onap.policy.apex.plugins.persistence.jpa.eclipselink.entities.ReferenceKeyTestEntity;
/**
- * Junit tests for class EclipselinkApexDao
- *
+ * Junit tests for class EclipselinkApexDao.
+ *
* @author Dinh Danh Le (dinh.danh.le@ericsson.com)
*
*/
public class EclipselinkApexDaoTest {
- private static final List<AxArtifactKey> TEST_ARTIKEYS = Arrays.asList(new AxArtifactKey[] {
- new AxArtifactKey("ABC", "0.0.1"), new AxArtifactKey("DEF", "0.1.1"), new AxArtifactKey("XYZ", "1.1.1")});
+ private static final List<AxArtifactKey> TEST_ARTIKEYS = Arrays.asList(new AxArtifactKey[]
+ { new AxArtifactKey("ABC", "0.0.1"), new AxArtifactKey("DEF", "0.1.1"), new AxArtifactKey("XYZ", "1.1.1") });
- private final DAOParameters daoParameters = new DAOParameters();
+ private final DaoParameters daoParameters = new DaoParameters();
private EclipselinkApexDao eclipselinkApexDao = null;
+ /**
+ * Setup the tests.
+ *
+ * @throws ApexException Exceptions from test setup
+ */
@Before
public void setup() throws ApexException {
- daoParameters.setPluginClass(EclipselinkApexDao.class.getCanonicalName());
+ daoParameters.setPluginClass(EclipselinkApexDao.class.getName());
daoParameters.setPersistenceUnit("DAOTest");
eclipselinkApexDao = new EclipselinkApexDao();
eclipselinkApexDao.init(daoParameters);
}
}
-
@Test
public void test_getArtifactByReferenceKey() {
final AxArtifactKey artifactKey = new AxArtifactKey("XXX", "0.0.1");
assertNull(eclipselinkApexDao.getArtifact(ReferenceKeyTestEntity.class, anotherReferenceKey));
// assert return only one entity when finding an entity with correct key
- final ReferenceKeyTestEntity retEntity =
- eclipselinkApexDao.getArtifact(ReferenceKeyTestEntity.class, referenceKey);
+ final ReferenceKeyTestEntity retEntity = eclipselinkApexDao.getArtifact(ReferenceKeyTestEntity.class,
+ referenceKey);
assertEquals(referenceKey, retEntity.getKey());
}
-
@Test
public void test_getArtifactByArtifactKey() {
final AxArtifactKey artifactKey = new AxArtifactKey("XXX", "0.0.1");
assertNull(eclipselinkApexDao.getArtifact(ArtifactKeyTestEntity.class, otherArtifactKey));
// assert return only one entity when finding an entity with correct key
- final ArtifactKeyTestEntity retEntity = eclipselinkApexDao.getArtifact(ArtifactKeyTestEntity.class, artifactKey);
+ final ArtifactKeyTestEntity retEntity = eclipselinkApexDao.getArtifact(ArtifactKeyTestEntity.class,
+ artifactKey);
assertNotNull(retEntity);
assertEquals(artifactKey, retEntity.getKey());
}
-
@Test
public void test_deleteByArtifactKey() {
// initialize a list of (3) entities corresponding to the list of testArtiKeys
assertEquals(100.0, remainingEntities.get(0).getDoubleValue(), 0.0);
}
-
@Test
public void test_deleteByReferenceKey() {
// prepare 2 AxArtifactKeys
final AxArtifactKey owner1Key = new AxArtifactKey("Owner1", "0.0.1");
// prepare a list of (3) AxReferenceKeys corresponding to owner0Key
- final List<AxReferenceKey> refKey0s =
- Arrays.asList(new AxReferenceKey[] {new AxReferenceKey(owner0Key, "Entity01"),
- new AxReferenceKey(owner0Key, "Entity02"), new AxReferenceKey(owner0Key, "Entity03")});
+ final List<AxReferenceKey> refKey0s = Arrays.asList(new AxReferenceKey[] {
+ new AxReferenceKey(owner0Key, "Entity01"),
+ new AxReferenceKey(owner0Key, "Entity02"),
+ new AxReferenceKey(owner0Key, "Entity03")
+ });
+
// prepare 2 more AxReferenceKeys corresponding to owner1Key
final AxReferenceKey refKey11 = new AxReferenceKey(owner1Key, "Entity11");
final AxReferenceKey refKey12 = new AxReferenceKey(owner1Key, "Entity12");
assertEquals(0, eclipselinkApexDao.getAll(ReferenceKeyTestEntity.class).size());
}
-
@Test
public void test_getAllByArtifactKey() {
final AxReferenceKey refKey0 = new AxReferenceKey(artiKey0, "Entity0");
final AxReferenceKey refKey1 = new AxReferenceKey(artiKey1, "Entity1");
-
// test with null class with known key --> return an empty list
assertNotNull(eclipselinkApexDao.getAll(null, artiKey1));
assertTrue(eclipselinkApexDao.getAll(null, artiKey1).equals(Collections.emptyList()));
assertEquals(200.0, retEntity.getDoubleValue(), 0);
}
-
-
}