Changeset 1419
- Timestamp:
- 06/14/11 09:28:53 (13 years ago)
- Location:
- ComponentRegistry/trunk/ComponentRegistry
- Files:
-
- 11 deleted
- 16 edited
Legend:
- Unmodified
- Added
- Removed
-
ComponentRegistry/trunk/ComponentRegistry/pom.xml
r1382 r1419 324 324 </executions> 325 325 </plugin> 326 <!--327 Assembly helper to create the RegistryFiller tool a command line tool which can help fill in a registry with328 existing components/profiles. Build the tool with: mvn -Dpackaging=jar -Dmaven.test.skip=true assembly:assembly329 This creates a in "target" a ComponentRegistry-1.0-SNAPSHOT-RegistryFiller directory with a bin and share330 directory. You can start the tool from the bin dir.331 -->332 <plugin>333 <groupId>org.apache.maven.plugins</groupId>334 <artifactId>maven-assembly-plugin</artifactId>335 <configuration>336 <attach>false</attach>337 <ignoreDirFormatExtensions>true</ignoreDirFormatExtensions>338 <descriptors>339 <descriptor>src/main/assembly/registryFiller.xml</descriptor>340 </descriptors>341 </configuration>342 </plugin>343 326 </plugins> 344 327 </build> -
ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/frontend/MassMigratePage.java
r1364 r1419 2 2 3 3 import java.io.Serializable; 4 import java.util.ArrayList;5 import java.util.List;6 4 7 5 import org.apache.wicket.Component; … … 18 16 import org.slf4j.LoggerFactory; 19 17 20 import clarin.cmdi.componentregistry.ComponentRegistry;21 import clarin.cmdi.componentregistry.ComponentRegistryException;22 import clarin.cmdi.componentregistry.MDMarshaller;23 import clarin.cmdi.componentregistry.components.CMDComponentSpec;24 import clarin.cmdi.componentregistry.impl.database.AbstractDescriptionDao;25 18 import clarin.cmdi.componentregistry.impl.database.ComponentDescriptionDao; 26 19 import clarin.cmdi.componentregistry.impl.database.ProfileDescriptionDao; 27 20 import clarin.cmdi.componentregistry.impl.database.UserDao; 28 import clarin.cmdi.componentregistry.impl.filesystem.ComponentRegistryFactoryImpl;29 import clarin.cmdi.componentregistry.model.AbstractDescription;30 import clarin.cmdi.componentregistry.model.UserMapping;31 import clarin.cmdi.componentregistry.model.UserMapping.User;32 21 33 22 /** … … 41 30 private final static Logger LOG = LoggerFactory.getLogger(MassMigratePage.class); 42 31 private FeedbackPanel feedback; 43 @SpringBean(name = "fileRegistryFactory") 44 private ComponentRegistryFactoryImpl fileRegistryFactory; 45 @SpringBean 46 private ComponentDescriptionDao componentDescriptionDao; 47 @SpringBean 48 private ProfileDescriptionDao profileDescriptionDao; 49 @SpringBean 50 private UserDao userDao; 51 private transient UserMapping userMap; 32 // @SpringBean 33 // private ComponentDescriptionDao componentDescriptionDao; 34 // @SpringBean 35 // private ProfileDescriptionDao profileDescriptionDao; 36 // @SpringBean 37 // private UserDao userDao; 52 38 53 39 public MassMigratePage(final PageParameters pageParameters) { 54 40 super(pageParameters); 55 userMap = fileRegistryFactory.getUserMap();56 41 addLinks(); 57 42 feedback = new FeedbackPanel("feedback") { … … 81 66 82 67 private void addMigrationOptions() { 83 add(new Label("migrate1Label", " Click here to start the migration of the file storage into the database."));68 add(new Label("migrate1Label", "No migration implemented at the moment...")); 84 69 add(new IndicatingAjaxLink("migrate1") { 85 70 … … 94 79 95 80 private void startMigration() { 96 info("Start Migration users..."); 97 List<User> users = userMap.getUsers(); 98 for (User user : users) { 99 userDao.insertUser(user); 100 } 101 info("Start Migration descriptions and content..."); 102 List<ComponentRegistry> registries = new ArrayList<ComponentRegistry>(); 103 registries.add(fileRegistryFactory.getPublicRegistry()); 104 registries.addAll(fileRegistryFactory.getAllUserRegistries()); 105 for (ComponentRegistry registry : registries) { 106 try { 107 migrateDescriptions(registry.getComponentDescriptions(), registry, componentDescriptionDao); 108 migrateDescriptions(registry.getProfileDescriptions(), registry, profileDescriptionDao); 109 } catch (ComponentRegistryException e) { 110 LOG.error("Error in migration, check the logs!", e); 111 info("Error cannot retrieve descriptions from registry " + registry.getName()); 112 } 113 } 114 info("End Migration."); 81 info("Nothing to migrate..."); 115 82 } 116 83 117 private void migrateDescriptions(List<? extends AbstractDescription> descs, ComponentRegistry registry, AbstractDescriptionDao descDao) {118 int migrateCount = 0;119 for (AbstractDescription description : descs) {120 try {121 User user = userDao.getByPrincipalName(userMap.findUser(description.getUserId()).getPrincipalName());122 descDao.insertDescription(description, getContent(description, registry), registry.isPublic(), user.getId());123 } catch (Exception e) {124 LOG.error("Error in migration:", e);125 info("Error cannot migrate, check the logs!" + description.getId());126 }127 migrateCount++;128 }129 LOG.info(registry.getName() + " migrated: " + migrateCount + " out of " + descs.size() + " descs");130 }131 132 private String getContent(AbstractDescription description, ComponentRegistry registry) throws ComponentRegistryException {133 CMDComponentSpec spec = null;134 if (description.isProfile()) {135 spec = registry.getMDProfile(description.getId());136 } else {137 spec = registry.getMDComponent(description.getId());138 }139 return MDMarshaller.marshalToString(spec);140 }141 84 } -
ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/frontend/SecureAdminWebPage.java
r1292 r1419 1 1 package clarin.cmdi.componentregistry.frontend; 2 2 3 import clarin.cmdi.componentregistry.Configuration;4 3 import java.security.Principal; 5 4 … … 8 7 import org.apache.wicket.markup.html.basic.MultiLineLabel; 9 8 10 import clarin.cmdi.componentregistry. impl.filesystem.FileSystemConfiguration;9 import clarin.cmdi.componentregistry.Configuration; 11 10 12 11 public abstract class SecureAdminWebPage extends WebPage { … … 18 17 setResponsePage(new AccessDeniedPage()); 19 18 } 20 add(new MultiLineLabel("message", "Component Registry Admin Page.\nYou are logged in as: " + userPrincipal.getName() 21 + ".\nRegistry is located in: " + FileSystemConfiguration.getInstance().getRegistryRoot())); 19 add(new MultiLineLabel("message", "Component Registry Admin Page.\nYou are logged in as: " + userPrincipal.getName() + ".\n")); 22 20 } 23 21 24 22 protected Principal getUserPrincipal() { 25 23 return getWebRequestCycle().getWebRequest().getHttpServletRequest().getUserPrincipal(); 26 24 } 27 25 -
ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/frontend/StatisticsPage.java
r1359 r1419 1 1 package clarin.cmdi.componentregistry.frontend; 2 2 3 import clarin.cmdi.componentregistry.ComponentRegistry;4 import clarin.cmdi.componentregistry.ComponentRegistryException;5 import clarin.cmdi.componentregistry.impl.filesystem.ComponentRegistryFactoryImpl;6 import clarin.cmdi.componentregistry.components.CMDComponentSpec;7 import clarin.cmdi.componentregistry.components.CMDComponentType;8 import clarin.cmdi.componentregistry.model.ComponentDescription;9 import clarin.cmdi.componentregistry.model.ProfileDescription;10 import clarin.cmdi.componentregistry.impl.filesystem.CMDComponentSpecExpanderImpl;11 import clarin.cmdi.componentregistry.impl.filesystem.ComponentRegistryImpl;12 import clarin.cmdi.componentregistry.components.CMDElementType;13 3 import java.io.IOException; 14 4 import java.util.List; 5 15 6 import org.apache.wicket.PageParameters; 16 7 import org.apache.wicket.markup.html.WebMarkupContainer; … … 18 9 import org.apache.wicket.markup.html.link.Link; 19 10 import org.apache.wicket.markup.repeater.RepeatingView; 11 import org.apache.wicket.spring.injection.annot.SpringBean; 12 13 import clarin.cmdi.componentregistry.ComponentRegistry; 14 import clarin.cmdi.componentregistry.ComponentRegistryException; 15 import clarin.cmdi.componentregistry.ComponentRegistryFactory; 16 import clarin.cmdi.componentregistry.components.CMDComponentSpec; 17 import clarin.cmdi.componentregistry.components.CMDComponentType; 18 import clarin.cmdi.componentregistry.components.CMDElementType; 19 import clarin.cmdi.componentregistry.impl.database.CMDComponentSpecExpanderDbImpl; 20 import clarin.cmdi.componentregistry.impl.database.ComponentRegistryDbImpl; 21 import clarin.cmdi.componentregistry.model.ComponentDescription; 22 import clarin.cmdi.componentregistry.model.ProfileDescription; 20 23 21 24 /** … … 26 29 27 30 private static final long serialVersionUID = 1L; 28 private transient ComponentRegistry registry = ComponentRegistryFactoryImpl.getInstance().getPublicRegistry(); 31 @SpringBean(name = "componentRegistryFactory") 32 private ComponentRegistryFactory componentRegistryFactory; 29 33 30 34 private static class Statistics { … … 36 40 public StatisticsPage(final PageParameters pageParameters) throws IOException, ComponentRegistryException { 37 41 super(pageParameters); 42 ComponentRegistry registry = componentRegistryFactory.getPublicRegistry(); 38 43 addLinks(); 39 DisplayStatistics();44 displayStatistics(registry); 40 45 } 41 46 42 private void DisplayStatistics() throws ComponentRegistryException {47 private void displayStatistics(ComponentRegistry registry) throws ComponentRegistryException { 43 48 List<ProfileDescription> profileList = registry.getProfileDescriptions(); 44 49 RepeatingView repeating = new RepeatingView("repeating"); … … 46 51 add(new Label("profilenumbermessage", "Current number of profiles in the component registry: " + profileList.size())); 47 52 for (ProfileDescription pd : profileList) { 48 displayProfileStatistics(pd, repeating );53 displayProfileStatistics(pd, repeating, registry); 49 54 } 50 55 List<ComponentDescription> componentList = registry.getComponentDescriptions(); … … 53 58 add(new Label("componentnumbermessage", "Current number of components in the component registry: " + componentList.size())); 54 59 for (ComponentDescription cd : componentList) { 55 displayComponentStatistics(cd, repeatingcomp );60 displayComponentStatistics(cd, repeatingcomp, registry); 56 61 } 57 62 } 58 63 59 private void displayProfileStatistics(ProfileDescription pd, RepeatingView repeatingview ) throws ComponentRegistryException {64 private void displayProfileStatistics(ProfileDescription pd, RepeatingView repeatingview, ComponentRegistry registry) throws ComponentRegistryException { 60 65 WebMarkupContainer item = new WebMarkupContainer(repeatingview.newChildId()); 61 66 repeatingview.add(item); 62 67 item.add(new Label("ID", pd.getId())); 63 68 item.add(new Label("profname", pd.getName())); 64 CMDComponentSpec profile = CMDComponentSpecExpander Impl.expandProfile(pd.getId(), (ComponentRegistryImpl) registry);69 CMDComponentSpec profile = CMDComponentSpecExpanderDbImpl.expandProfile(pd.getId(), (ComponentRegistryDbImpl) registry); 65 70 Statistics stats = new Statistics(); 66 71 componentCounter(profile.getCMDComponent(), stats); … … 70 75 } 71 76 72 private void displayComponentStatistics(ComponentDescription cd, RepeatingView repeatingview ) throws ComponentRegistryException {77 private void displayComponentStatistics(ComponentDescription cd, RepeatingView repeatingview, ComponentRegistry registry) throws ComponentRegistryException { 73 78 WebMarkupContainer item = new WebMarkupContainer(repeatingview.newChildId()); 74 79 repeatingview.add(item); 75 80 item.add(new Label("ID", cd.getId())); 76 81 item.add(new Label("compname", cd.getName())); 77 CMDComponentSpec compspec = CMDComponentSpecExpander Impl.expandComponent(cd.getId(), (ComponentRegistryImpl) registry);82 CMDComponentSpec compspec = CMDComponentSpecExpanderDbImpl.expandComponent(cd.getId(), (ComponentRegistryDbImpl) registry); 78 83 Statistics stats = new Statistics(); 79 84 componentCounter(compspec.getCMDComponent(), stats); -
ComponentRegistry/trunk/ComponentRegistry/src/main/webresources/WEB-INF/applicationContext.xml
r1342 r1419 9 9 10 10 <import resource="spring-config/component-registry.xml"/> 11 <!-- <import resource="spring-config/filesystem-impl.xml"/>-->12 11 <import resource="spring-config/database-impl.xml"/> 13 12 14 <!-- For migration -->15 <bean id="fileSystemConfiguration" class="clarin.cmdi.componentregistry.impl.filesystem.FileSystemConfiguration" init-method="init" factory-method="getInstance">16 <property name="registryRoot" value="${registryRoot}" />17 </bean>18 <bean id="fileRegistryFactory" class="clarin.cmdi.componentregistry.impl.filesystem.ComponentRegistryFactoryImpl" init-method="init" factory-method="getInstance">19 <property name="configuration" ref="configuration"/>20 <property name="fileSystemConfiguration" ref="fileSystemConfiguration"/>21 </bean>22 <!-- For migration end -->23 13 24 14 </beans> -
ComponentRegistry/trunk/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/impl/database/AbstractDescriptionDaoTest.java
r1378 r1419 22 22 */ 23 23 @RunWith(SpringJUnit4ClassRunner.class) 24 @ContextConfiguration(locations = { "/applicationContext -database-impl.xml" })24 @ContextConfiguration(locations = { "/applicationContext.xml" }) 25 25 public abstract class AbstractDescriptionDaoTest { 26 26 -
ComponentRegistry/trunk/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/impl/database/AdminRegistryTest.java
r1373 r1419 1 1 package clarin.cmdi.componentregistry.impl.database; 2 2 3 import static clarin.cmdi.componentregistry.impl.database.ComponentRegistryDatabase.createTableComponentDescription;4 import static clarin.cmdi.componentregistry.impl.database.ComponentRegistryDatabase.createTableProfileDescription;5 import static clarin.cmdi.componentregistry.impl.database.ComponentRegistryDatabase.createTableRegistryUser;6 import static clarin.cmdi.componentregistry.impl.database.ComponentRegistryDatabase.createTableXmlContent;7 import static clarin.cmdi.componentregistry.impl.database.ComponentRegistryDatabase.resetDatabase;8 3 import static org.junit.Assert.assertEquals; 9 4 import static org.junit.Assert.assertTrue; … … 26 21 import clarin.cmdi.componentregistry.frontend.DisplayDataNode; 27 22 import clarin.cmdi.componentregistry.frontend.SubmitFailedException; 28 import clarin.cmdi.componentregistry.impl.database.ComponentDescriptionDao;29 import clarin.cmdi.componentregistry.impl.database.ProfileDescriptionDao;30 23 import clarin.cmdi.componentregistry.model.ComponentDescription; 31 24 import clarin.cmdi.componentregistry.model.ProfileDescription; … … 34 27 35 28 @RunWith(SpringJUnit4ClassRunner.class) 36 @ContextConfiguration(locations = {"/applicationContext -database-impl.xml"})29 @ContextConfiguration(locations = {"/applicationContext.xml"}) 37 30 public class AdminRegistryTest { 38 31 … … 50 43 @Before 51 44 public void init() { 52 resetDatabase(jdbcTemplate); 53 createTableComponentDescription(jdbcTemplate); 54 createTableProfileDescription(jdbcTemplate); 55 createTableXmlContent(jdbcTemplate); 56 createTableRegistryUser(jdbcTemplate); 45 ComponentRegistryDatabase.resetAndCreateAllTables(jdbcTemplate); 57 46 } 58 47 -
ComponentRegistry/trunk/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/impl/database/ComponentRegistryDatabase.java
r1369 r1419 61 61 + " principal_name character varying);"); 62 62 } 63 64 public static void resetAndCreateAllTables(JdbcTemplate jdbcTemplate) { 65 resetDatabase(jdbcTemplate); 66 createTableComponentDescription(jdbcTemplate); 67 createTableProfileDescription(jdbcTemplate); 68 createTableXmlContent(jdbcTemplate); 69 createTableRegistryUser(jdbcTemplate); 70 } 63 71 } -
ComponentRegistry/trunk/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/impl/database/ComponentRegistryDbImplTest.java
r1386 r1419 37 37 38 38 @RunWith(SpringJUnit4ClassRunner.class) 39 @ContextConfiguration(locations = {"/applicationContext -database-impl.xml"})39 @ContextConfiguration(locations = {"/applicationContext.xml"}) 40 40 public class ComponentRegistryDbImplTest { 41 41 … … 51 51 @Before 52 52 public void init() { 53 resetDatabase(jdbcTemplate); 54 createTableComponentDescription(jdbcTemplate); 55 createTableProfileDescription(jdbcTemplate); 56 createTableXmlContent(jdbcTemplate); 57 createTableRegistryUser(jdbcTemplate); 53 ComponentRegistryDatabase.resetAndCreateAllTables(jdbcTemplate); 58 54 } 59 55 -
ComponentRegistry/trunk/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/impl/database/ComponentRegistryFactoryDbImplTest.java
r1359 r1419 23 23 */ 24 24 @RunWith(SpringJUnit4ClassRunner.class) 25 @ContextConfiguration(locations = {"/applicationContext -database-impl.xml"})25 @ContextConfiguration(locations = {"/applicationContext.xml"}) 26 26 public class ComponentRegistryFactoryDbImplTest { 27 27 -
ComponentRegistry/trunk/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/impl/database/UserDaoTest.java
r1324 r1419 20 20 */ 21 21 @RunWith(SpringJUnit4ClassRunner.class) 22 @ContextConfiguration(locations = {"/applicationContext -database-impl.xml"})22 @ContextConfiguration(locations = {"/applicationContext.xml"}) 23 23 public class UserDaoTest { 24 24 -
ComponentRegistry/trunk/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/rest/ComponentRegistryRestServiceTestCase.java
r1345 r1419 6 6 7 7 8 import clarin.cmdi.componentregistry.impl.database.UserDao; 8 9 import clarin.cmdi.componentregistry.model.ComponentDescription; 9 10 import clarin.cmdi.componentregistry.model.ProfileDescription; 11 import clarin.cmdi.componentregistry.model.UserMapping.User; 10 12 11 13 import com.sun.jersey.api.client.GenericType; … … 20 22 import com.sun.jersey.test.framework.JerseyTest; 21 23 import com.sun.jersey.test.framework.WebAppDescriptor; 24 25 import org.springframework.beans.factory.annotation.Autowired; 22 26 import org.springframework.web.context.ContextLoaderListener; 23 27 import org.springframework.web.context.request.RequestContextListener; … … 31 35 }; 32 36 37 @Autowired 38 private UserDao userDao; 39 40 33 41 protected abstract String getApplicationContextFile(); 34 42 … … 59 67 + new String(Base64.encode(DummyPrincipal.DUMMY_PRINCIPAL.getName() + ":dummy"))); 60 68 } 69 70 protected void createUserRecord() { 71 User user = new User(); 72 user.setName("Database test user"); 73 user.setPrincipalName(DummyPrincipal.DUMMY_PRINCIPAL.getName()); 74 userDao.insertUser(user); 75 } 76 77 protected UserDao getUserDao() { 78 return userDao; 79 } 61 80 62 81 } -
ComponentRegistry/trunk/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/rest/DbImplComponentRegistryRestServiceTest.java
r1348 r1419 1 1 package clarin.cmdi.componentregistry.rest; 2 2 3 import clarin.cmdi.componentregistry.ComponentRegistry;4 import clarin.cmdi.componentregistry.ComponentRegistryFactory;5 import clarin.cmdi.componentregistry.impl.database.ComponentRegistryBeanFactory;6 import clarin.cmdi.componentregistry.impl.database.ComponentRegistryDatabase;7 import clarin.cmdi.componentregistry.impl.database.UserDao;8 import clarin.cmdi.componentregistry.model.UserMapping.User;9 3 import org.junit.Before; 10 4 import org.junit.runner.RunWith; … … 14 8 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 15 9 10 import clarin.cmdi.componentregistry.ComponentRegistry; 11 import clarin.cmdi.componentregistry.ComponentRegistryFactory; 12 import clarin.cmdi.componentregistry.impl.database.ComponentRegistryBeanFactory; 13 import clarin.cmdi.componentregistry.impl.database.ComponentRegistryDatabase; 14 16 15 17 16 @RunWith(SpringJUnit4ClassRunner.class) 18 @ContextConfiguration(locations = {"/applicationContext -database-impl.xml"})17 @ContextConfiguration(locations = {"/applicationContext.xml"}) 19 18 public class DbImplComponentRegistryRestServiceTest extends ComponentRegistryRestServiceTest { 20 19 @Autowired … … 24 23 @Autowired 25 24 private JdbcTemplate jdbcTemplate; 26 @Autowired 27 private UserDao userDao; 25 28 26 private ComponentRegistry testRegistry; 29 27 … … 31 29 @Before 32 30 public void init() { 33 ComponentRegistryDatabase.resetDatabase(jdbcTemplate); 34 ComponentRegistryDatabase.createTableRegistryUser(jdbcTemplate); 35 ComponentRegistryDatabase.createTableXmlContent(jdbcTemplate); 36 ComponentRegistryDatabase.createTableProfileDescription(jdbcTemplate); 37 ComponentRegistryDatabase.createTableComponentDescription(jdbcTemplate); 31 ComponentRegistryDatabase.resetAndCreateAllTables(jdbcTemplate); 38 32 createUserRecord(); 39 33 setUpTestRegistry(); 40 }41 42 private void createUserRecord(){43 User user = new User();44 user.setName("Database test user");45 user.setPrincipalName(DummyPrincipal.DUMMY_PRINCIPAL.getName());46 userDao.insertUser(user);47 34 } 48 35 … … 54 41 @Override 55 42 protected String getApplicationContextFile() { 56 return "classpath:applicationContext -database-impl.xml";43 return "classpath:applicationContext.xml"; 57 44 } 58 45 … … 64 51 @Override 65 52 protected String expectedUserId(String principal) { 66 return userDao.getByPrincipalName(principal).getId().toString();53 return getUserDao().getByPrincipalName(principal).getId().toString(); 67 54 } 68 55 -
ComponentRegistry/trunk/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/rest/DbImplConcurrentRestServiceTest.java
r1359 r1419 1 1 package clarin.cmdi.componentregistry.rest; 2 2 3 import clarin.cmdi.componentregistry.impl.database.ComponentRegistryDatabase;4 import clarin.cmdi.componentregistry.impl.database.UserDao;5 import clarin.cmdi.componentregistry.model.UserMapping.User;6 3 import org.junit.Before; 7 4 import org.junit.runner.RunWith; … … 11 8 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 12 9 10 import clarin.cmdi.componentregistry.impl.database.ComponentRegistryDatabase; 11 13 12 @RunWith(SpringJUnit4ClassRunner.class) 14 @ContextConfiguration(locations = { "/applicationContext-database-impl.xml"})13 @ContextConfiguration(locations = { "/applicationContext.xml" }) 15 14 public class DbImplConcurrentRestServiceTest extends ConcurrentRestServiceTest { 16 15 17 16 @Autowired 18 17 private JdbcTemplate jdbcTemplate; 19 @Autowired20 private UserDao userDao;21 // private ComponentRegistry testRegistry;22 18 23 19 @Before 24 20 public void init() { 25 ComponentRegistryDatabase.resetDatabase(jdbcTemplate); 26 ComponentRegistryDatabase.createTableRegistryUser(jdbcTemplate); 27 ComponentRegistryDatabase.createTableXmlContent(jdbcTemplate); 28 ComponentRegistryDatabase.createTableProfileDescription(jdbcTemplate); 29 ComponentRegistryDatabase.createTableComponentDescription(jdbcTemplate); 21 ComponentRegistryDatabase.resetAndCreateAllTables(jdbcTemplate); 30 22 createUserRecord(); 31 // setUpTestRegistry();32 23 } 33 34 private void createUserRecord() {35 User user = new User();36 user.setName("Database test user");37 user.setPrincipalName(DummyPrincipal.DUMMY_PRINCIPAL.getName());38 userDao.insertUser(user);39 }40 //41 // private void setUpTestRegistry() {42 // // Get public component registry43 // testRegistry = componentRegistryBeanFactory.getNewComponentRegistry();44 // }45 24 46 25 @Override 47 26 protected String getApplicationContextFile() { 48 49 return "classpath:applicationContext-database-impl.xml"; 27 return "classpath:applicationContext.xml"; 50 28 } 51 29 } -
ComponentRegistry/trunk/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/rest/MDValidatorTest.java
r1286 r1419 6 6 7 7 import java.io.ByteArrayInputStream; 8 import java.io.File;9 8 import java.io.InputStream; 10 import java.text.ParseException;11 9 12 import javax.xml.bind.JAXBException;13 14 import org.junit.After;15 10 import org.junit.Before; 16 11 import org.junit.Test; 12 import org.junit.runner.RunWith; 13 import org.springframework.beans.factory.annotation.Autowired; 14 import org.springframework.jdbc.core.JdbcTemplate; 15 import org.springframework.test.context.ContextConfiguration; 16 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 17 17 18 18 import clarin.cmdi.componentregistry.ComponentRegistry; 19 19 import clarin.cmdi.componentregistry.ComponentRegistryFactory; 20 import clarin.cmdi.componentregistry.impl. filesystem.ComponentRegistryTestCase;20 import clarin.cmdi.componentregistry.impl.database.ComponentRegistryDatabase; 21 21 import clarin.cmdi.componentregistry.model.ComponentDescription; 22 22 import clarin.cmdi.componentregistry.model.ProfileDescription; 23 import org.junit.runner.RunWith;24 import org.springframework.beans.factory.annotation.Autowired;25 import org.springframework.test.context.ContextConfiguration;26 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;27 23 28 24 @RunWith(SpringJUnit4ClassRunner.class) 29 25 @ContextConfiguration(locations={"/applicationContext.xml"}) 26 public class MDValidatorTest { 27 28 @Autowired 29 private ComponentRegistryFactory componentRegistryFactory; 30 @Autowired 31 private JdbcTemplate jdbcTemplate; 30 32 31 public class MDValidatorTest { 32 @Autowired 33 protected ComponentRegistryFactory componentRegistryFactory; 34 35 private static File registryDir; 36 private static ComponentRegistry testRegistry; 37 private static ComponentRegistry publicRegistry; 33 private ComponentRegistry publicRegistry; 38 34 39 35 @Before 40 public void setUpTestRegistry() throws ParseException, JAXBException { 41 registryDir = ComponentRegistryTestCase.createTempRegistryDir(); 42 testRegistry = ComponentRegistryTestCase.getTestRegistry(registryDir); 43 publicRegistry = testRegistry; 44 } 45 46 @After 47 public void deleteRegistry() { 48 ComponentRegistryTestCase.cleanUpRegistryDir(registryDir); 36 public void init() { 37 ComponentRegistryDatabase.resetAndCreateAllTables(jdbcTemplate); 38 publicRegistry = componentRegistryFactory.getPublicRegistry(); 49 39 } 50 40 … … 67 57 68 58 ProfileDescription desc = ProfileDescription.createNewDescription(); 69 MDValidator validator = new MDValidator(input, desc, testRegistry, null, publicRegistry);59 MDValidator validator = new MDValidator(input, desc, publicRegistry, null, publicRegistry); 70 60 assertTrue(validator.validate()); 71 61 } … … 83 73 84 74 ProfileDescription desc = ProfileDescription.createNewDescription(); 85 MDValidator validator = new MDValidator(input, desc, testRegistry, null, publicRegistry);75 MDValidator validator = new MDValidator(input, desc, publicRegistry, null, publicRegistry); 86 76 assertFalse(validator.validate()); 87 77 assertTrue(validator.getErrorMessages().get(0).startsWith(MDValidator.COMPONENT_NOT_PUBLICLY_REGISTERED_ERROR)); … … 103 93 104 94 ProfileDescription desc = ProfileDescription.createNewDescription(); 105 MDValidator validator = new MDValidator(new ByteArrayInputStream(profileContent.getBytes()), desc, testRegistry, null, publicRegistry);95 MDValidator validator = new MDValidator(new ByteArrayInputStream(profileContent.getBytes()), desc, publicRegistry, null, publicRegistry); 106 96 assertFalse(validator.validate()); 107 97 assertEquals(2, validator.getErrorMessages().size()); … … 109 99 assertTrue(validator.getErrorMessages().get(1).startsWith(MDValidator.COMPONENT_NOT_PUBLICLY_REGISTERED_ERROR)); 110 100 111 RegistryTestHelper.addComponent( testRegistry, id1);112 validator = new MDValidator(new ByteArrayInputStream(profileContent.getBytes()), desc, testRegistry, null, publicRegistry);101 RegistryTestHelper.addComponent(publicRegistry, id1); 102 validator = new MDValidator(new ByteArrayInputStream(profileContent.getBytes()), desc, publicRegistry, null, publicRegistry); 113 103 assertFalse(validator.validate()); 114 104 assertEquals(1, validator.getErrorMessages().size()); 115 105 assertTrue(validator.getErrorMessages().get(0).startsWith(MDValidator.COMPONENT_NOT_PUBLICLY_REGISTERED_ERROR)); 116 106 117 RegistryTestHelper.addComponent( testRegistry, id2);118 validator = new MDValidator(new ByteArrayInputStream(profileContent.getBytes()), desc, testRegistry, null, publicRegistry);107 RegistryTestHelper.addComponent(publicRegistry, id2); 108 validator = new MDValidator(new ByteArrayInputStream(profileContent.getBytes()), desc, publicRegistry, null, publicRegistry); 119 109 assertTrue("component is registered should be valid now", validator.validate()); 120 110 assertEquals(0, validator.getErrorMessages().size()); … … 144 134 145 135 RegistryTestHelper.addComponent(userRegistry, id1); 146 RegistryTestHelper.addComponent( testRegistry, id2);147 validator = new MDValidator(new ByteArrayInputStream(profileContent.getBytes()), desc, testRegistry, null, publicRegistry);136 RegistryTestHelper.addComponent(publicRegistry, id2); 137 validator = new MDValidator(new ByteArrayInputStream(profileContent.getBytes()), desc, publicRegistry, null, publicRegistry); 148 138 assertFalse(validator.validate()); 149 139 assertEquals(1, validator.getErrorMessages().size()); … … 171 161 172 162 ComponentDescription desc = ComponentDescription.createNewDescription(); 173 MDValidator validator = new MDValidator(new ByteArrayInputStream(content.getBytes()), desc, testRegistry, null, publicRegistry);163 MDValidator validator = new MDValidator(new ByteArrayInputStream(content.getBytes()), desc, publicRegistry, null, publicRegistry); 174 164 assertFalse(validator.validate()); 175 165 assertEquals(1, validator.getErrorMessages().size()); 176 166 assertTrue(validator.getErrorMessages().get(0).startsWith(MDValidator.COMPONENT_NOT_PUBLICLY_REGISTERED_ERROR)); 177 167 178 RegistryTestHelper.addComponent( testRegistry, id1);179 validator = new MDValidator(new ByteArrayInputStream(content.getBytes()), desc, testRegistry, null, publicRegistry);168 RegistryTestHelper.addComponent(publicRegistry, id1); 169 validator = new MDValidator(new ByteArrayInputStream(content.getBytes()), desc, publicRegistry, null, publicRegistry); 180 170 assertTrue(validator.validate()); 181 171 assertEquals(0, validator.getErrorMessages().size()); -
ComponentRegistry/trunk/ComponentRegistry/src/test/resources/applicationContext.xml
r1345 r1419 9 9 10 10 <import resource="spring-config/component-registry.xml"/> 11 <import resource="spring-config/filesystem-impl.xml"/> 11 <import resource="spring-config/database-impl.xml"/> 12 12 13 13 14 </beans>
Note: See TracChangeset
for help on using the changeset viewer.