Search in sources :

Example 1 with InMemPackageReader

use of org.sablo.InMemPackageReader in project servoy-client by Servoy.

the class ValuelistPropTest method getTestComponents.

@Override
protected InMemPackageReader getTestComponents() throws IOException {
    InputStream is = getClass().getResourceAsStream("ValuelistTest.manifest");
    byte[] bytes = new byte[is.available()];
    is.read(bytes);
    String manifest = new String(bytes);
    is.close();
    is = getClass().getResourceAsStream("ValuelistTest-mycomponent.spec");
    bytes = new byte[is.available()];
    is.read(bytes);
    String comp1 = new String(bytes);
    is.close();
    HashMap<String, String> components = new HashMap<>();
    components.put("mycomponent.spec", comp1);
    InMemPackageReader inMemPackageReader = new InMemPackageReader(manifest, components);
    return inMemPackageReader;
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) InputStream(java.io.InputStream) InMemPackageReader(org.sablo.InMemPackageReader)

Example 2 with InMemPackageReader

use of org.sablo.InMemPackageReader in project servoy-client by Servoy.

the class WebComponentSpecTest method testLibsWithAngularEnry.

@Test
public void testLibsWithAngularEnry() throws JSONException {
    String property = "{name:'test',definition:'/test.js', libraries:[{name:'angular-animate', version:'1.5.8', url:'js/angular-modules/1.9.0/angular-animate.js', mimetype:'text/javascript'},{name:'something', version:'1', url:'/something.js', mimetype:'text/javascript'}],model: {}}";
    String manifest = "Manifest-Version: 1.0\nAnt-Version: Apache Ant 1.8.4\nCreated-By: 1.7.0_05-b06 (Oracle Corporation)\n\nName: mycomponent.spec\nWeb-Component: True\n";
    HashMap<String, String> components = new HashMap<>();
    components.put("mycomponent.spec", property);
    WebComponentSpecProvider.init(new IPackageReader[] { new InMemPackageReader(manifest, components) }, null);
    WebServiceSpecProvider.init(new IPackageReader[0]);
    Object[] contributions = IndexPageEnhancer.getAllContributions(null, null, null, null);
    Assert.assertTrue(((Collection<?>) contributions[0]).size() == 0);
    Assert.assertTrue(((Collection<?>) contributions[1]).size() == 3);
    Assert.assertTrue(contributions[1].toString(), ((Collection<?>) contributions[1]).contains("js/angular-modules/1.9.0/angular-animate.js"));
    contributions = IndexPageEnhancer.getAllContributions(null, null, null, NGClientEntryFilter.CONTRIBUTION_ENTRY_FILTER);
    Assert.assertTrue(((Collection<?>) contributions[0]).size() == 0);
    Assert.assertTrue(((Collection<?>) contributions[1]).size() == 3);
    Assert.assertTrue(contributions[1].toString(), ((Collection<?>) contributions[1]).contains("js/angular-modules/1.9.0/angular-animate.js"));
}
Also used : HashMap(java.util.HashMap) Collection(java.util.Collection) InMemPackageReader(org.sablo.InMemPackageReader) Test(org.junit.Test)

Example 3 with InMemPackageReader

use of org.sablo.InMemPackageReader in project servoy-client by Servoy.

the class PersistFieldInstanceTest method getTestComponents.

@Override
protected InMemPackageReader getTestComponents() throws IOException {
    InputStream is = getClass().getResourceAsStream("WebComponentTest.manifest");
    byte[] bytes = new byte[is.available()];
    is.read(bytes);
    String manifest = new String(bytes);
    is.close();
    is = getClass().getResourceAsStream("WebComponentTest-mycomponent.spec");
    bytes = new byte[is.available()];
    is.read(bytes);
    String comp = new String(bytes);
    is.close();
    HashMap<String, String> components = new HashMap<>();
    components.put("mycomponent.spec", comp);
    InMemPackageReader inMemPackageReader = new InMemPackageReader(manifest, components);
    return inMemPackageReader;
}
Also used : HashMap(java.util.HashMap) InputStream(java.io.InputStream) InMemPackageReader(org.sablo.InMemPackageReader)

Example 4 with InMemPackageReader

use of org.sablo.InMemPackageReader in project servoy-client by Servoy.

the class PropertySetTest method getTestComponents.

@Override
protected InMemPackageReader getTestComponents() throws IOException {
    InputStream is = getClass().getResourceAsStream("PropertyTests.manifest");
    byte[] bytes = new byte[is.available()];
    is.read(bytes);
    String manifest = new String(bytes);
    is.close();
    is = getClass().getResourceAsStream("mycomponent.spec");
    bytes = new byte[is.available()];
    is.read(bytes);
    String comp1 = new String(bytes);
    is.close();
    HashMap<String, String> components = new HashMap<>();
    components.put("mycomponent.spec", comp1);
    InMemPackageReader inMemPackageReader = new InMemPackageReader(manifest, components);
    return inMemPackageReader;
}
Also used : HashMap(java.util.HashMap) InputStream(java.io.InputStream) InMemPackageReader(org.sablo.InMemPackageReader)

Example 5 with InMemPackageReader

use of org.sablo.InMemPackageReader in project servoy-client by Servoy.

the class AbstractSolutionTest method buildSolution.

@Before
public void buildSolution() throws Exception {
    TestNGClient.initSettings();
    Types.getTypesInstance().registerTypes();
    final File f = new File(NGClient.class.getProtectionDomain().getCodeSource().getLocation().getPath());
    IPackageReader[] servicesReaders = null;
    IPackageReader[] componentsReaders = null;
    InMemPackageReader inMemPackageReader = getTestComponents();
    if (f.isFile() && f.getName().startsWith("servoy_ngclient") && f.getName().endsWith(".jar")) {
        // it is running from bundles/jars
        ZipFile zipFile = new ZipFile(f);
        componentsReaders = inMemPackageReader != null ? new IPackageReader[] { new ZipPackageReader(zipFile, "war/servoycore/"), new ZipPackageReader(zipFile, "war/servoydefault/"), inMemPackageReader } : new IPackageReader[] { new ZipPackageReader(zipFile, "war/servoycore/"), new ZipPackageReader(zipFile, "war/servoydefault/") };
        servicesReaders = new IPackageReader[] { new ZipPackageReader(zipFile, "war/servoyservices/") };
    } else {
        // it is running from sources/projects
        File ngClientProjDir = f;
        if (!new File(ngClientProjDir, "/war/servoycore/").exists()) {
            ngClientProjDir = ngClientProjDir.getParentFile();
        }
        componentsReaders = getReaders(new File[] { new File(ngClientProjDir.getAbsoluteFile() + "/war/servoycore/"), new File(ngClientProjDir.getAbsoluteFile() + "/war/servoydefault/") }, // in eclipse we .. out of bin, in jenkins we .. out of @dot
        inMemPackageReader);
        servicesReaders = getReaders(new File[] { new File(ngClientProjDir.getAbsoluteFile(), "/war/servoyservices/") }, null);
    }
    WebComponentSpecProvider.init(componentsReaders, DefaultComponentPropertiesProvider.instance);
    WebServiceSpecProvider.init(servicesReaders);
    final TestRepository tr = new TestRepository();
    try {
        ApplicationServerRegistry.setApplicationServerSingleton(new TestApplicationServer(tr));
        UUID uuid = UUID.randomUUID();
        final RootObjectMetaData metadata = tr.createRootObjectMetaData(tr.getElementIdForUUID(uuid), uuid, "Test", IRepository.SOLUTIONS, 1, 1);
        solution = (Solution) tr.createRootObject(metadata);
        tr.cacheRootObject(solution);
        solution.setChangeHandler(new ChangeHandler(tr));
        fillTestSolution();
        HttpSession testHttpsession = new TestHttpsession();
        endpoint = new NGClientEndpoint() {

            // for testing onstart of the NGClientEndpoint should not run
            @Override
            public void onStart() {
            }

            @Override
            protected HttpSession getHttpSession(Session session) {
                return testHttpsession;
            }
        };
        NGClientWebsocketSession session = new NGClientWebsocketSession(new WebsocketSessionKey(testHttpsession.getId(), 1)) {

            @Override
            public void init(Map<String, List<String>> requestParams) throws Exception {
            // override default init, shouldnt make another client.
            }

            @Override
            protected IEventDispatcher createEventDispatcher() {
                return new TestNGEventDispatcher(endpoint);
            }
        };
        WebsocketSessionManager.addSession(session);
        NGClientWebsocketSessionWindows windows = new NGClientWebsocketSessionWindows(session);
        CurrentWindow.set(windows);
        client = new TestNGClient(tr, session) {

            @Override
            public boolean loadSolutionsAndModules(SolutionMetaData solutionMetaData) {
                boolean b = super.loadSolutionsAndModules(solutionMetaData);
                IPersistIndex index = PersistIndexCache.getCachedIndex(solution);
                solution.getChangeHandler().addIPersistListener((IItemChangeListener<IPersist>) index);
                try {
                    setupData();
                } catch (ServoyException e) {
                    e.printStackTrace();
                }
                return b;
            }
        };
        J2DBGlobals.setServiceProvider(client);
        client.setUseLoginSolution(false);
        endpoint.start(new TestSession(), String.valueOf(session.getSessionKey().getClientnr()), "null", "42");
        CurrentWindow.set(session.getWindows().iterator().next());
    } catch (RepositoryException e) {
        e.printStackTrace();
        Assert.fail(e.getMessage());
    }
}
Also used : RootObjectMetaData(com.servoy.j2db.persistence.RootObjectMetaData) IPackageReader(org.sablo.specification.Package.IPackageReader) ServoyException(com.servoy.j2db.util.ServoyException) ChangeHandler(com.servoy.j2db.persistence.ChangeHandler) InMemPackageReader(org.sablo.InMemPackageReader) UUID(com.servoy.j2db.util.UUID) UUID.randomUUID(java.util.UUID.randomUUID) HttpSession(javax.servlet.http.HttpSession) NGClientWebsocketSessionWindows(com.servoy.j2db.server.ngclient.eventthread.NGClientWebsocketSessionWindows) RepositoryException(com.servoy.j2db.persistence.RepositoryException) SolutionMetaData(com.servoy.j2db.persistence.SolutionMetaData) NGClientEndpoint(com.servoy.j2db.server.ngclient.endpoint.NGClientEndpoint) ZipFile(java.util.zip.ZipFile) WebsocketSessionKey(org.sablo.websocket.WebsocketSessionKey) NGClientWebsocketSession(com.servoy.j2db.server.ngclient.NGClientWebsocketSession) IPersistIndex(com.servoy.j2db.IPersistIndex) ZipFile(java.util.zip.ZipFile) File(java.io.File) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) HttpSession(javax.servlet.http.HttpSession) Session(javax.websocket.Session) NGClientWebsocketSession(com.servoy.j2db.server.ngclient.NGClientWebsocketSession) IItemChangeListener(com.servoy.j2db.persistence.IItemChangeListener) Before(org.junit.Before)

Aggregations

InMemPackageReader (org.sablo.InMemPackageReader)9 HashMap (java.util.HashMap)8 InputStream (java.io.InputStream)7 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 Before (org.junit.Before)3 IPersistIndex (com.servoy.j2db.IPersistIndex)1 ChangeHandler (com.servoy.j2db.persistence.ChangeHandler)1 IItemChangeListener (com.servoy.j2db.persistence.IItemChangeListener)1 RepositoryException (com.servoy.j2db.persistence.RepositoryException)1 RootObjectMetaData (com.servoy.j2db.persistence.RootObjectMetaData)1 SolutionMetaData (com.servoy.j2db.persistence.SolutionMetaData)1 NGClientWebsocketSession (com.servoy.j2db.server.ngclient.NGClientWebsocketSession)1 NGClientEndpoint (com.servoy.j2db.server.ngclient.endpoint.NGClientEndpoint)1 NGClientWebsocketSessionWindows (com.servoy.j2db.server.ngclient.eventthread.NGClientWebsocketSessionWindows)1 ServoyException (com.servoy.j2db.util.ServoyException)1 UUID (com.servoy.j2db.util.UUID)1 File (java.io.File)1 Collection (java.util.Collection)1 Map (java.util.Map)1 UUID.randomUUID (java.util.UUID.randomUUID)1