package org.wso2.registry.secure; import junit.framework.TestCase; import org.wso2.registry.*; import org.wso2.registry.jdbc.JDBCRegistry; import org.wso2.registry.jdbc.realm.RegistryRealm; import org.wso2.registry.jdbc.utils.RegistryDataSource; import org.wso2.registry.users.UserRealm; import org.wso2.registry.users.UserStoreException; import org.wso2.usermanager.UserManagerException; import javax.sql.DataSource; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.util.Map; public class DataPopulate extends TestCase { private static Registry registry = null; private static RegistryRealm realm = null; int maxResourceCount = 3000; int maxUserCount = 100; int maxRoleCount = 10; int maxFileToputCollections = 100; int maxFileToputResource = 100; DataSource dataSource = null; public DataPopulate(String text) { super(text); } public void setUp() { try { dataSource = new RegistryDataSource("jdbc:derby://localhost:1527/derbyDB", "org.apache.derby.jdbc.ClientDriver","reg","reg"); //dataSource = new RegistryDataSource("jdbc:hsqldb:mem:aname","org.hsqldb.jdbcDriver","","sa"); realm = new RegistryRealm(dataSource); registry = new JDBCRegistry(dataSource, realm); }catch (Exception e) { fail("Failed to initialize the registry."); e.printStackTrace(); } } public void testpopulateResources() throws RegistryException { SecureRegistry adminRegistry = new SecureRegistry(RegistryConstants.ADMIN_USER, "admin", registry, realm); for (int i=1;i<=maxResourceCount;i++){ String path_1= "/c"+i; String path_2= path_1 + "/b" +i; String path= path_2+"/r1.txt"; try { Resource r1 = adminRegistry.newResource(); r1.setDescription("This is a file to be renamed"); String fileContent = "This is file the content"; for (int filec=1;filec<=5;filec++){ fileContent += fileContent; } byte[] r1content = (fileContent).getBytes(); r1.setContent(r1content); r1.setMediaType("txt"); Comment c1 = new Comment(); c1.setResourcePath(path); c1.setText("This is a test comment1"); Comment c2 = new Comment(); c2.setResourcePath(path); c2.setText("This is a test comment2"); r1.setProperty("key1", "value1"); r1.setProperty("key2", "value2"); r1.setProperty("key3", "value3"); r1.setProperty("key4", "value4"); adminRegistry.put(path,r1); adminRegistry.addComment(path,c1); adminRegistry.addComment(path,c2); adminRegistry.applyTag(path, "tag1"); adminRegistry.applyTag(path, "tag2"); adminRegistry.applyTag(path, "tag3"); adminRegistry.rateResource(path, 4); }catch (RegistryException e) { e.printStackTrace(); } } System.out.println("End of creating"+" "+maxResourceCount+" Resources"); } /* public void testAddDependency() throws RegistryException { for (int i=1;i<=maxResourceCount;i++){ String path_1= "/c"+i; String path_2= path_1 + "/b" +i; String path= path_2+"/r1.txt"; if ((i+1)