/* * Copyright 2015 herd contributors * * 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. */ package org.finra.herd.dao; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import java.util.Arrays; import java.util.List; import org.junit.Test; import org.finra.herd.model.api.xml.BusinessObjectFormatKey; import org.finra.herd.model.api.xml.CustomDdlKey; import org.finra.herd.model.jpa.CustomDdlEntity; public class CustomDdlDaoTest extends AbstractDaoTest { @Test public void testGetCustomDdlByKey() { // Create and persist a custom DDL entity. CustomDdlEntity customDdlEntity = customDdlDaoTestHelper .createCustomDdlEntity(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, CUSTOM_DDL_NAME, TEST_DDL); // Retrieve the custom DDL. CustomDdlEntity resultCustomDdlEntity = customDdlDao.getCustomDdlByKey(new CustomDdlKey(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, CUSTOM_DDL_NAME)); // Validate the returned object. assertEquals(customDdlEntity.getId(), resultCustomDdlEntity.getId()); } @Test public void testGetCustomDdls() { // List of test custom DDL names. List<String> testCustomDdlNames = Arrays.asList(CUSTOM_DDL_NAME, CUSTOM_DDL_NAME_2); // Create and persist a custom DDL entities. for (String customDdlName : testCustomDdlNames) { customDdlDaoTestHelper .createCustomDdlEntity(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, customDdlName, TEST_DDL); } // Retrieve a list of custom DDL keys. List<CustomDdlKey> resultCustomDdlKeys = customDdlDao.getCustomDdls(new BusinessObjectFormatKey(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION)); // Validate the returned object. assertNotNull(resultCustomDdlKeys); assertEquals(testCustomDdlNames.size(), resultCustomDdlKeys.size()); for (int i = 0; i < testCustomDdlNames.size(); i++) { assertEquals(new CustomDdlKey(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, testCustomDdlNames.get(i)), resultCustomDdlKeys.get(i)); } } }