Package org.auraframework.system

Examples of org.auraframework.system.AuraContext


    private void runTestRequestFromDifferentBrowserOnSamePage(String ua, Type uaType, String cssMsgToVerify) throws Exception {
      String cmpname = "appCache:withpreload";
      String cmporapp = "app";
      DefDescriptor<ApplicationDef> appDesc = DefDescriptorImpl.getInstance(cmpname,
          ApplicationDef.class);
        AuraContext context = Aura.getContextService()
                .startContext(Mode.DEV, AuraContext.Format.CSS, AuraContext.Authentication.AUTHENTICATED, appDesc);
        Client clientWEBKIT = new Client(ua);
        assertEquals(uaType,clientWEBKIT.getType());
    context.setClient(clientWEBKIT);
    final String uid = context.getDefRegistry().getUid(null, appDesc);
        context.addLoaded(appDesc, uid);
        Mode mode = context.getMode();
        final boolean minify = !(mode.isTestMode() || mode.isDevMode());
        final String mKey = minify ? "MIN:" : "DEV:";

        DummyHttpServletRequest request = new DummyHttpServletRequest(){
            @Override
            public long getDateHeader(String name) {
                return -1;
            }
        };
        request.setQueryParam(AuraResourceRewriteFilter.TYPE_PARAM, cmporapp);
        HttpServletResponse response = new DummyHttpServletResponse();
        AuraResourceServlet servlet = new AuraResourceServlet();
        servlet.doGet(request, response);

        final String key = "CSS:" + context.getClient().getType() + "$" + mKey + uid;
        // Verify something was actually added to cache
        String cssCache = context.getDefRegistry().getCachedString(uid, appDesc, key);
        assertNotNull("Nothing added to CSS cache", cssCache);
        if(!cssMsgToVerify.isEmpty()) {
          assertTrue(cssCache.contains(cssMsgToVerify));
        }
       
View Full Code Here


     * story: W-1450222
     */
    public void testCssCacheClearedOnSourceChange() throws Exception {
        DefDescriptor<ApplicationDef> appDesc = DefDescriptorImpl.getInstance("appCache:withpreload",
                ApplicationDef.class);
        AuraContext context = Aura.getContextService()
                .startContext(Mode.DEV, AuraContext.Format.CSS, AuraContext.Authentication.AUTHENTICATED, appDesc);
        final String uid = context.getDefRegistry().getUid(null, appDesc);
        context.addLoaded(appDesc, uid);
        Mode mode = context.getMode();
        final boolean minify = !(mode.isTestMode() || mode.isDevMode());
        final String mKey = minify ? "MIN:" : "DEV:";

        DummyHttpServletRequest request = new DummyHttpServletRequest(){
            @Override
            public long getDateHeader(String name) {
                return -1;
            }
        };
        request.setQueryParam(AuraResourceRewriteFilter.TYPE_PARAM, "app");
        HttpServletResponse response = new DummyHttpServletResponse();
        AuraResourceServlet servlet = new AuraResourceServlet();
        servlet.doGet(request, response);

        final String key = "CSS:" + context.getClient().getType() + "$" + mKey + uid;

        // Verify something was actually added to cache
        String cssCache = context.getDefRegistry().getCachedString(uid, appDesc, key);
        assertNotNull("Nothing added to CSS cache", cssCache);

        // Now force a source change event and verify cache is emptied
        Aura.getDefinitionService().onSourceChanged(null, SourceListener.SourceMonitorEvent.CHANGED, null);

        cssCache = context.getDefRegistry().getCachedString(uid, appDesc, key);
        Aura.getContextService().endContext();

        assertNull("CSS cache not cleared after source change event", cssCache);
    }
View Full Code Here

     * FIXME: this test should not be here.... it should be on MDR.
     */
    public void testJsCacheClearedOnSourceChange() throws Exception {
        DefDescriptor<ApplicationDef> appDesc = DefDescriptorImpl.getInstance("appCache:withpreload",
                ApplicationDef.class);
        AuraContext context = Aura.getContextService()
                .startContext(Mode.DEV, AuraContext.Format.JS, AuraContext.Authentication.AUTHENTICATED, appDesc);
        final String uid = context.getDefRegistry().getUid(null, appDesc);
        context.addLoaded(appDesc, uid);
        Mode mode = context.getMode();
        final boolean minify = !(mode.isTestMode() || mode.isDevMode());
        final String mKey = minify ? "MIN:" : "DEV:";

        DummyHttpServletRequest request = new DummyHttpServletRequest(){
            @Override
            public long getDateHeader(String name) {
                return -1;
            }
        };
        request.setQueryParam(AuraResourceRewriteFilter.TYPE_PARAM, "app");
        HttpServletResponse response = new DummyHttpServletResponse();
        AuraResourceServlet servlet = new AuraResourceServlet();
        servlet.doGet(request, response);

        final String key = "JS:" + mKey + uid;

        // Verify something was actually added to cache
        String jsCache = context.getDefRegistry().getCachedString(uid, appDesc, key);
        assertNotNull("Nothing added to JS cache", jsCache);

        // Now force a source change event and verify cache is emptied
        Aura.getDefinitionService().onSourceChanged(null, SourceListener.SourceMonitorEvent.CHANGED, null);

        jsCache = context.getDefRegistry().getCachedString(uid, appDesc, key);
        Aura.getContextService().endContext();
        assertNull("JS cache not cleared after source change event", jsCache);
    }
View Full Code Here

     *
     * @throws Exception
     */
    public void testObserverInvoked() throws Exception {
        IntegrationServiceObserver mockObserver = Mockito.mock(IntegrationServiceObserver.class);
        AuraContext cntx = Aura.getContextService().startContext(Mode.UTEST, Format.JSON, Authentication.AUTHENTICATED);
        Integration integration = service.createIntegration("", Mode.UTEST, true, null, getNoDefaultPreloadsApp().getQualifiedName(), mockObserver);
        injectSimpleComponent(integration);
        Mockito.verify(mockObserver, Mockito.times(2)).contextEstablished(integration, cntx);
    }
View Full Code Here

    }

    @Override
    protected void readAttributes() throws QuickFixException {
        super.readAttributes();
        AuraContext context = Aura.getContextService().getCurrentContext();
        context.pushCallingDescriptor(getDefDescriptor());
        try {
            String extendsNames = getAttributeValue(ATTRIBUTE_EXTENDS);
            if (extendsNames != null) {
                for (String extendsName : AuraTextUtil.splitSimple(",", extendsNames)) {
                    builder.extendsDescriptors.add(DefDescriptorImpl.getInstance(extendsName.trim(), InterfaceDef.class));
                }
            }

            String providerName = getAttributeValue(ATTRIBUTE_PROVIDER);
            if (providerName != null) {
                List<String> providerNames = AuraTextUtil.splitSimpleAndTrim(providerName, ",", 0);
                for (String provider : providerNames) {
                    builder.addProvider(provider);
                }
            } else {
                String apexProviderName = String.format("apex://%s.%sProvider", defDescriptor.getNamespace(),
                        AuraTextUtil.initCap(defDescriptor.getName()));
                DefDescriptor<ProviderDef> apexDescriptor = DefDescriptorImpl.getInstance(apexProviderName,
                        ProviderDef.class);
                if (apexDescriptor.exists()) {
                    builder.addProvider(apexDescriptor.getQualifiedName());
                }
            }

            builder.setAccess(readAccessAttribute());
        } finally {
            context.popCallingDescriptor();
        }
    }
View Full Code Here

    }

    private void writeApplication(Appendable out) throws IOException, AuraRuntimeException, QuickFixException {
        if (isSupportedClient(client)) {
            // ensure that we have a context.
            AuraContext context = getContext(null);
            try {
                ApplicationDef appDef = getApplicationDescriptor(application).getDef();

                if (observer != null) {
                    observer.beforeApplicationWritten(this, context, appDef);
View Full Code Here

    }

    @SuppressWarnings("unchecked")
    @Override
    protected void readAttributes() throws QuickFixException {
        AuraContext context = Aura.getContextService().getCurrentContext();
        MasterDefRegistry mdr = context.getDefRegistry();
        context.pushCallingDescriptor(builder.getDescriptor());
        try {
            Mode mode = context.getMode();

            super.readAttributes();
            String controllerName = getAttributeValue(ATTRIBUTE_CONTROLLER);
            DefDescriptor<ControllerDef> controllerDescriptor = null;
            if (controllerName != null) {
                controllerDescriptor = DefDescriptorImpl.getInstance(
                        controllerName, ControllerDef.class);
            } else {
                String apexControllerName = String.format("apex://%s.%sController",
                        defDescriptor.getNamespace(),
                        AuraTextUtil.initCap(defDescriptor.getName()));
                DefDescriptor<ControllerDef> apexDescriptor = DefDescriptorImpl
                        .getInstance(apexControllerName, ControllerDef.class);
                if (mdr.exists(apexDescriptor)) {
                    controllerDescriptor = apexDescriptor;
                }
            }

            if (controllerDescriptor != null) {
                builder.controllerDescriptors.add(controllerDescriptor);
            }

            String modelName = getAttributeValue(ATTRIBUTE_MODEL);
            if (modelName != null) {
                builder.modelDefDescriptor = DefDescriptorImpl.getInstance(
                        modelName, ModelDef.class);
            } else {
                String jsModelName = String.format("js://%s.%s",
                        defDescriptor.getNamespace(), defDescriptor.getName());
                DefDescriptor<ModelDef> jsDescriptor = DefDescriptorImpl
                        .getInstance(jsModelName, ModelDef.class);
                if (mdr.exists(jsDescriptor)) {
                    builder.modelDefDescriptor = jsDescriptor;
                } else {
                    String apexModelName = String.format("apex://%s.%sModel",
                            defDescriptor.getNamespace(),
                            AuraTextUtil.initCap(defDescriptor.getName()));
                    DefDescriptor<ModelDef> apexDescriptor = DefDescriptorImpl
                            .getInstance(apexModelName, ModelDef.class);
                    if (mdr.exists(apexDescriptor)) {
                        builder.modelDefDescriptor = apexDescriptor;
                    }
                }
            }

            // See if there is a clientController that has the same qname.
            String jsDescriptorName = String.format("js://%s.%s",
                    defDescriptor.getNamespace(), defDescriptor.getName());
            DefDescriptor<ControllerDef> jsDescriptor = DefDescriptorImpl
                    .getInstance(jsDescriptorName, ControllerDef.class);
            if (mdr.exists(jsDescriptor)) {
                builder.controllerDescriptors.add(jsDescriptor);
            }

            //
            // TODO: W-1501702
            // Need to handle dual renderers for aura:placeholder
            //
            String rendererName = getAttributeValue(ATTRIBUTE_RENDERER);
            if (rendererName != null) {
                List<String> rendererNames = AuraTextUtil.splitSimpleAndTrim(
                        rendererName, ",", 0);
                for (String renderer : rendererNames) {
                    builder.addRenderer(renderer);
                }

            } else {
                // See if there is a clientRenderer that has the same qname.
                DefDescriptor<RendererDef> jsRendererDescriptor = DefDescriptorImpl
                        .getInstance(jsDescriptorName, RendererDef.class);
                if (mdr.exists(jsRendererDescriptor)) {
                    builder.addRenderer(jsRendererDescriptor.getQualifiedName());
                }
            }

            String helperName = getAttributeValue(ATTRIBUTE_HELPER);
            if (helperName != null) {
                List<String> helperNames = AuraTextUtil.splitSimpleAndTrim(
                        helperName, ",", 0);
                for (String helper : helperNames) {
                    builder.addHelper(helper);
                }

            } else {
                // See if there is a helper that has the same qname.
                DefDescriptor<HelperDef> jsHelperDescriptor = DefDescriptorImpl
                        .getInstance(jsDescriptorName, HelperDef.class);
                if (mdr.exists(jsHelperDescriptor)) {
                    builder.addHelper(jsHelperDescriptor.getQualifiedName());
                }
            }

            DefDescriptor<ResourceDef> jsResourceDescriptor = DefDescriptorImpl
                    .getInstance(jsDescriptorName, ResourceDef.class);
            if (mdr.exists(jsResourceDescriptor)) {
                builder.addResource(jsResourceDescriptor.getQualifiedName());
            }

            // See if there is a style that has the same qname.
            String styleName = getAttributeValue(ATTRIBUTE_STYLE);
            if (AuraTextUtil.isNullEmptyOrWhitespace(styleName)) {
                styleName = String.format("css://%s.%s",
                        defDescriptor.getNamespace(), defDescriptor.getName());
            }
            DefDescriptor<StyleDef> cssDescriptor = DefDescriptorImpl.getInstance(
                    styleName, StyleDef.class);
            if (mdr.exists(cssDescriptor)) {
                builder.styleDescriptor = cssDescriptor;
            }

            DefDescriptor<ResourceDef> cssResourceDescriptor = DefDescriptorImpl.getInstance(styleName,
                    ResourceDef.class);
            if (mdr.exists(cssResourceDescriptor)) {
                builder.addResource(cssResourceDescriptor.getQualifiedName());
            }

            // See if there is a themedef that has the same qname. todo -- add cmpTheme attr as well?
            String themeName = String.format("%s:%s", defDescriptor.getNamespace(), defDescriptor.getName());
            DefDescriptor<ThemeDef> themeDesc = DefDescriptorImpl.getInstance(themeName, ThemeDef.class);
            if (mdr.exists(themeDesc)) {
                builder.cmpThemeDescriptor = themeDesc;
            }

            // Do not consider Javascript Test suite defs in PROD and PRODDEBUG modes.
            if (mode != Mode.PROD && mode != Mode.PRODDEBUG) {
                // See if there is a test suite that has the same qname.
                DefDescriptor<TestSuiteDef> jsTestSuiteDescriptor = DefDescriptorImpl
                        .getInstance(jsDescriptorName, TestSuiteDef.class);
                if (mdr.exists(jsTestSuiteDescriptor)) {
                    builder.testSuiteDefDescriptor = jsTestSuiteDescriptor;
                }
            }
            String extendsName = getAttributeValue(ATTRIBUTE_EXTENDS);
            if (extendsName != null) {
                builder.extendsDescriptor = DefDescriptorImpl.getInstance(
                        extendsName, (Class<T>) defDescriptor.getDefType()
                                .getPrimaryInterface());
            }

            String implementsNames = getAttributeValue(ATTRIBUTE_IMPLEMENTS);
            if (implementsNames != null) {
                for (String implementsName : AuraTextUtil.splitSimple(",",
                        implementsNames)) {
                    builder.interfaces.add(DefDescriptorImpl.getInstance(
                            implementsName.trim(), InterfaceDef.class));
                }
            }

            builder.isAbstract = getBooleanAttributeValue(ATTRIBUTE_ABSTRACT);
            // if a component is abstract, it should be extensible by default
            if (builder.isAbstract
                    && getAttributeValue(ATTRIBUTE_EXTENSIBLE) == null) {
                builder.isExtensible = true;
            } else {
                builder.isExtensible = getBooleanAttributeValue(ATTRIBUTE_EXTENSIBLE);
            }

            String providerName = getAttributeValue(ATTRIBUTE_PROVIDER);

            if (providerName != null) {
                List<String> providerNames = AuraTextUtil.splitSimpleAndTrim(
                        providerName, ",", 0);
                for (String provider : providerNames) {
                    builder.addProvider(provider);
                }
            } else {
                String apexProviderName = String.format("apex://%s.%sProvider",
                        defDescriptor.getNamespace(),
                        AuraTextUtil.initCap(defDescriptor.getName()));
                DefDescriptor<ProviderDef> apexDescriptor = DefDescriptorImpl
                        .getInstance(apexProviderName, ProviderDef.class);
                if (mdr.exists(apexDescriptor)) {
                    builder.addProvider(apexDescriptor.getQualifiedName());
                }
            }

            String templateName = getAttributeValue(ATTRIBUTE_TEMPLATE);
            if (templateName != null) {
                builder.templateDefDescriptor = DefDescriptorImpl.getInstance(
                        templateName, ComponentDef.class);
            }

            DefDescriptor<DocumentationDef> documentationDescriptor = DefDescriptorImpl.getAssociateDescriptor(
                    builder.getDescriptor(), DocumentationDef.class, DefDescriptor.MARKUP_PREFIX);

            if (mdr.exists(documentationDescriptor)) {
                builder.setDocumentation(documentationDescriptor.getQualifiedName());
            }

            DefDescriptor<DesignDef> designDescriptor = DefDescriptorImpl.getAssociateDescriptor(
                    builder.getDescriptor(), DesignDef.class, DefDescriptor.MARKUP_PREFIX);

            if (mdr.exists(designDescriptor)) {
                builder.designDefDescriptor = designDescriptor;
            }

            builder.render = getAttributeValue(ATTRIBUTE_RENDER);

            String whitespaceVal = getAttributeValue(ATTRIBUTE_WHITESPACE);
            builder.whitespaceBehavior = whitespaceVal == null ? WhitespaceBehavior.OPTIMIZE
                    : WhitespaceBehavior.valueOf(whitespaceVal.toUpperCase());

            builder.isTemplate = getBooleanAttributeValue(ATTRIBUTE_ISTEMPLATE);

            builder.setAccess(readAccessAttribute());
        } finally {
            context.popCallingDescriptor();
        }
    }
View Full Code Here

    private MasterDefRegistryImpl getDefRegistry(boolean asMocks) {
        Collection<RegistryAdapter> providers = AuraImpl.getRegistryAdapters();
        List<DefRegistry<?>> mdrregs = Lists.newArrayList();

        AuraContext context = Aura.getContextService().getCurrentContext();
        for (RegistryAdapter provider : providers) {
            DefRegistry<?>[] registries = provider.getRegistries(context.getMode(), context.getAccess(), null);
            if (registries != null) {
                for (DefRegistry<?> reg : registries) {
                    Set<String> ns = reg.getNamespaces();

                    if (ns != null) {
View Full Code Here

        List<ClientLibraryDef> libDefs = mdr.getClientLibraries(null);
        assertNull(libDefs);

        DefDescriptor<ApplicationDef> appDesc = Aura.getDefinitionService().getDefDescriptor(
                "clientLibraryTest:testDependencies", ApplicationDef.class);
        AuraContext cntx = Aura.getContextService().getCurrentContext();
        cntx.setApplicationDescriptor(appDesc);
        Aura.getDefinitionService().updateLoaded(appDesc);

        libDefs = mdr.getClientLibraries(cntx.getUid(appDesc));

        // 13 from clientLibraryTest:testDependencies and its dependencies + 4 from aura:component
        // Update this number when you add new aura:clientLibrary tags to these components
        assertEquals(16, libDefs.size());
    }
View Full Code Here

    }

    private MasterDefRegistry restartContextGetNewMDR() {
        // simulate new request
        MasterDefRegistry mdr = getAuraMDR();
        AuraContext ctx = Aura.getContextService().getCurrentContext();
        Mode mode = ctx.getMode();
        Format format = ctx.getFormat();
        Authentication access = ctx.getAccess();
        Aura.getContextService().endContext();

        Aura.getContextService().startContext(mode, format, access);
        MasterDefRegistry mdr2 = getAuraMDR();
        assertFalse("MasterDefRegistry should be different after restart of context", mdr == mdr2);
View Full Code Here

TOP

Related Classes of org.auraframework.system.AuraContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.