25 |
26 |
27 |
--------------------------------------------------------------------------------
/components/org.wso2.carbon.uiserver/src/test/resources/testng.xml:
--------------------------------------------------------------------------------
1 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/tests/distribution/carbon-home/wso2/default/deployment/web-ui-apps/test/configuration.yaml:
--------------------------------------------------------------------------------
1 | #
2 | # Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
3 | #
4 | # WSO2 Inc. licenses this file to you under the Apache License,
5 | # Version 2.0 (the "License"); you may not use this file except
6 | # in compliance with the License.
7 | # You may obtain a copy of the License at
8 | #
9 | # http://www.apache.org/licenses/LICENSE-2.0
10 | #
11 | # Unless required by applicable law or agreed to in writing,
12 | # software distributed under the License is distributed on an
13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 | # KIND, either express or implied. See the License for the
15 | # specific language governing permissions and limitations
16 | # under the License.
17 | #
18 |
19 | # HTTP response headers.
20 | responseHeaders:
21 | # HTTP response headers for static resources.
22 | resources:
23 | "Content-Security-Policy": "default-src 'none'; script-src 'self' ssl.google-analytics.com;"
24 | # HTTP response headers for pages.
25 | pages:
26 | "X-Frame-Options": "DENY"
27 |
--------------------------------------------------------------------------------
/components/org.wso2.carbon.uiserver/src/test/java/org/wso2/carbon/uiserver/api/ServerConfigurationTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
3 | *
4 | * WSO2 Inc. licenses this file to you under the Apache License,
5 | * Version 2.0 (the "License"); you may not use this file except
6 | * in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing,
12 | * software distributed under the License is distributed on an
13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 | * KIND, either express or implied. See the License for the
15 | * specific language governing permissions and limitations
16 | * under the License.
17 | */
18 |
19 | package org.wso2.carbon.uiserver.api;
20 |
21 | import org.testng.Assert;
22 | import org.testng.annotations.Test;
23 |
24 | /**
25 | * Test cases for {@link ServerConfiguration} class.
26 | *
27 | * @since 0.12.6
28 | */
29 | public class ServerConfigurationTest {
30 |
31 | @Test
32 | public void testGetContextPaths() {
33 | ServerConfiguration serverConfiguration = new ServerConfiguration();
34 | Assert.assertFalse(serverConfiguration.getConfigurationForApp("foo").isPresent());
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/components/org.wso2.carbon.uiserver/src/test/java/org/wso2/carbon/uiserver/internal/impl/HtmlPageTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
3 | *
4 | * WSO2 Inc. licenses this file to you under the Apache License,
5 | * Version 2.0 (the "License"); you may not use this file except
6 | * in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing,
12 | * software distributed under the License is distributed on an
13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 | * KIND, either express or implied. See the License for the
15 | * specific language governing permissions and limitations
16 | * under the License.
17 | */
18 |
19 | package org.wso2.carbon.uiserver.internal.impl;
20 |
21 | import org.testng.Assert;
22 | import org.testng.annotations.Test;
23 | import org.wso2.carbon.uiserver.api.UriPatten;
24 |
25 | /**
26 | * Test cases for {@link HtmlPage} class.
27 | *
28 | * @since 0.12.5
29 | */
30 | public class HtmlPageTest {
31 |
32 | @Test
33 | public void testRender() {
34 | String pageContent = "
some html
";
35 | HtmlPage page = new HtmlPage(new UriPatten("/"), pageContent);
36 | Assert.assertEquals(page.render(null, null), pageContent);
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/components/org.wso2.carbon.uiserver/src/test/java/org/wso2/carbon/uiserver/internal/io/util/MimeMapperTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
3 | *
4 | * WSO2 Inc. licenses this file to you under the Apache License,
5 | * Version 2.0 (the "License"); you may not use this file except
6 | * in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing,
12 | * software distributed under the License is distributed on an
13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 | * KIND, either express or implied. See the License for the
15 | * specific language governing permissions and limitations
16 | * under the License.
17 | */
18 |
19 | package org.wso2.carbon.uiserver.internal.io.util;
20 |
21 | import org.testng.Assert;
22 | import org.testng.annotations.Test;
23 |
24 | /**
25 | * Test cases for {@link MimeMapper} class.
26 | *
27 | * @since 0.12.5
28 | */
29 | public class MimeMapperTest {
30 |
31 | @Test
32 | public void testGetMimeType() {
33 | Assert.assertTrue(MimeMapper.getMimeType("jpeg").isPresent());
34 | Assert.assertEquals(MimeMapper.getMimeType("jpeg").orElse(null), "image/jpeg");
35 | Assert.assertFalse(MimeMapper.getMimeType("foo").isPresent());
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/components/org.wso2.carbon.uiserver/src/main/java/org/wso2/carbon/uiserver/spi/Server.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
3 | *
4 | * WSO2 Inc. licenses this file to you under the Apache License,
5 | * Version 2.0 (the "License"); you may not use this file except
6 | * in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing,
12 | * software distributed under the License is distributed on an
13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 | * KIND, either express or implied. See the License for the
15 | * specific language governing permissions and limitations
16 | * under the License.
17 | */
18 |
19 | package org.wso2.carbon.uiserver.spi;
20 |
21 | import org.wso2.carbon.uiserver.api.App;
22 |
23 | import java.util.Optional;
24 |
25 | /**
26 | * Represents Carbon UI server.
27 | *
28 | * @since 0.8.0
29 | */
30 | public interface Server {
31 |
32 | /**
33 | * Returns fully deployed web app with the specified name.
34 | *
35 | * @param appName name of the app
36 | * @return app with the specified name; {@link Optional#empty() empty} if there is no app with the given name or app
37 | * is not deployed yet
38 | */
39 | Optional getApp(String appName);
40 | }
41 |
--------------------------------------------------------------------------------
/tests/distribution/carbon-home/deployment/web-ui-apps/test/pages/index.hbs:
--------------------------------------------------------------------------------
1 |
18 |
19 |
20 |
21 | TEST
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/tests/distribution/carbon.product:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/components/org.wso2.carbon.uiserver/src/main/java/org/wso2/carbon/uiserver/internal/reference/PageReference.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
3 | *
4 | * WSO2 Inc. licenses this file to you under the Apache License,
5 | * Version 2.0 (the "License"); you may not use this file except
6 | * in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing,
12 | * software distributed under the License is distributed on an
13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 | * KIND, either express or implied. See the License for the
15 | * specific language governing permissions and limitations
16 | * under the License.
17 | */
18 |
19 | package org.wso2.carbon.uiserver.internal.reference;
20 |
21 | import org.wso2.carbon.uiserver.internal.exception.FileOperationException;
22 |
23 | /**
24 | * A reference to a page in a web app.
25 | *
26 | * @since 0.8.0
27 | */
28 | public interface PageReference {
29 |
30 | /**
31 | * Returns the path pattern of the page represented by this reference.
32 | *
33 | * @return path pattern of the page
34 | * @throws FileOperationException if cannot get the path pattern
35 | */
36 | String getPathPattern() throws FileOperationException;
37 |
38 | /**
39 | * Returns a reference to the HTMl if of the page represented by this reference.
40 | *
41 | * @return reference to the HTML file of the page
42 | */
43 | FileReference getHtmlFile();
44 | }
45 |
--------------------------------------------------------------------------------
/components/org.wso2.carbon.uiserver/src/main/java/org/wso2/carbon/uiserver/internal/reference/ThemeReference.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
3 | *
4 | * WSO2 Inc. licenses this file to you under the Apache License,
5 | * Version 2.0 (the "License"); you may not use this file except
6 | * in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing,
12 | * software distributed under the License is distributed on an
13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 | * KIND, either express or implied. See the License for the
15 | * specific language governing permissions and limitations
16 | * under the License.
17 | */
18 |
19 | package org.wso2.carbon.uiserver.internal.reference;
20 |
21 | import org.wso2.carbon.uiserver.internal.exception.FileOperationException;
22 |
23 | /**
24 | * A reference to a theme in a web app artifact.
25 | *
26 | * @since 0.8.0
27 | */
28 | public interface ThemeReference {
29 |
30 | /**
31 | * Returns the name of the theme represented by this reference.
32 | *
33 | * @return name of the theme
34 | * @throws FileOperationException if cannot read theme name
35 | */
36 | String getName() throws FileOperationException;
37 |
38 | /**
39 | * Returns the absolute path to the theme represented by this reference.
40 | *
41 | * @return absolute path to the theme
42 | * @throws FileOperationException if cannot obtain the path
43 | */
44 | String getPath() throws FileOperationException;
45 | }
46 |
--------------------------------------------------------------------------------
/tests/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
19 |
20 |
21 | 4.0.0
22 |
23 | org.wso2.carbon.uiserver.tests
24 | tests-parent
25 | pom
26 |
27 | WSO2 Carbon UI Server - Tests
28 | WSO2 Carbon UI Server tests
29 | http://wso2.org
30 |
31 |
32 | org.wso2.carbon.uiserver
33 | uis-parent
34 | 0.19.3-SNAPSHOT
35 | ../pom.xml
36 |
37 |
38 |
39 | distribution
40 |
41 |
42 |
43 |
--------------------------------------------------------------------------------
/components/org.wso2.carbon.uiserver/src/test/java/org/wso2/carbon/uiserver/api/http/HttpResponseTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
3 | *
4 | * WSO2 Inc. licenses this file to you under the Apache License,
5 | * Version 2.0 (the "License"); you may not use this file except
6 | * in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing,
12 | * software distributed under the License is distributed on an
13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 | * KIND, either express or implied. See the License for the
15 | * specific language governing permissions and limitations
16 | * under the License.
17 | */
18 |
19 | package org.wso2.carbon.uiserver.api.http;
20 |
21 | import org.testng.Assert;
22 | import org.testng.annotations.Test;
23 |
24 | /**
25 | * Test cases for {@link HttpResponse} class.
26 | *
27 | * @since 0.13.0
28 | */
29 | public class HttpResponseTest {
30 |
31 | @Test
32 | public void test() {
33 | HttpResponse response = new HttpResponse(HttpResponse.STATUS_OK, "some-content",
34 | HttpResponse.CONTENT_TYPE_TEXT_PLAIN);
35 |
36 | Assert.assertEquals(response.getStatus(), HttpResponse.STATUS_OK);
37 | Assert.assertEquals(response.getContent(), "some-content");
38 | Assert.assertEquals(response.getContentType(), HttpResponse.CONTENT_TYPE_TEXT_PLAIN);
39 | Assert.assertTrue(response.getHeaders().isEmpty());
40 | Assert.assertTrue(response.getCookies().isEmpty());
41 | Assert.assertNotNull(response.toString());
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/components/org.wso2.carbon.uiserver/src/main/java/org/wso2/carbon/uiserver/spi/RestApiProvider.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
3 | *
4 | * WSO2 Inc. licenses this file to you under the Apache License,
5 | * Version 2.0 (the "License"); you may not use this file except
6 | * in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing,
12 | * software distributed under the License is distributed on an
13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 | * KIND, either express or implied. See the License for the
15 | * specific language governing permissions and limitations
16 | * under the License.
17 | */
18 |
19 | package org.wso2.carbon.uiserver.spi;
20 |
21 | import org.wso2.carbon.uiserver.api.App;
22 | import org.wso2.msf4j.Microservice;
23 |
24 | import java.util.Map;
25 |
26 | /**
27 | * Provider that supplies microservices that should be deployed as REST APIs for a specified web app.
28 | *
29 | * @since 0.15.0
30 | */
31 | public interface RestApiProvider {
32 |
33 | /**
34 | * Returns the name of the app that this provider supplies REST APIs.
35 | *
36 | * @return name of the app
37 | */
38 | String getAppName();
39 |
40 | /**
41 | * Returns microservices that needs to be deployed as REST APIs.
42 | *
43 | * Key of the returning map is considered as the path (without the app context path) of the REST API.
44 | *
45 | * @param app app that returning microservices belong to
46 | * @return microservices to be deploy
47 | */
48 | Map getMicroservices(App app);
49 | }
50 |
--------------------------------------------------------------------------------
/components/org.wso2.carbon.uiserver/src/main/java/org/wso2/carbon/uiserver/internal/reference/I18nResourceReference.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
3 | *
4 | * WSO2 Inc. licenses this file to you under the Apache License,
5 | * Version 2.0 (the "License"); you may not use this file except
6 | * in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing,
12 | * software distributed under the License is distributed on an
13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 | * KIND, either express or implied. See the License for the
15 | * specific language governing permissions and limitations
16 | * under the License.
17 | */
18 |
19 | package org.wso2.carbon.uiserver.internal.reference;
20 |
21 | import org.wso2.carbon.uiserver.internal.exception.FileOperationException;
22 |
23 | import java.util.Locale;
24 | import java.util.Map;
25 |
26 | /**
27 | * A reference to an i18n resource in a web app artifact.
28 | *
29 | * @since 0.8.0
30 | */
31 | public interface I18nResourceReference {
32 |
33 | /**
34 | * Returns the locale of the i18n resource represented by this reference.
35 | *
36 | * @return locale of the i18n resource
37 | * @throws FileOperationException if cannot read the locale
38 | */
39 | Locale getLocale() throws FileOperationException;
40 |
41 | /**
42 | * Returns the messages of the i18n resource represented by this reference.
43 | *
44 | * @return messages of the i18n resource
45 | * @throws FileOperationException if cannot read the messages
46 | */
47 | Map getMessages() throws FileOperationException;
48 | }
49 |
--------------------------------------------------------------------------------
/components/org.wso2.carbon.uiserver/src/main/java/org/wso2/carbon/uiserver/internal/deployment/AppDeploymentEventListener.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
3 | *
4 | * WSO2 Inc. licenses this file to you under the Apache License,
5 | * Version 2.0 (the "License"); you may not use this file except
6 | * in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing,
12 | * software distributed under the License is distributed on an
13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 | * KIND, either express or implied. See the License for the
15 | * specific language governing permissions and limitations
16 | * under the License.
17 | */
18 |
19 | package org.wso2.carbon.uiserver.internal.deployment;
20 |
21 | import org.wso2.carbon.uiserver.api.App;
22 | import org.wso2.carbon.uiserver.internal.exception.AppDeploymentEventListenerException;
23 |
24 | /**
25 | * A listener that observes web app deployments.
26 | *
27 | * @since 0.8.3
28 | */
29 | public interface AppDeploymentEventListener {
30 |
31 | /**
32 | * Invoked when an app is deployed.
33 | *
34 | * @param app the deployed app
35 | * @throws AppDeploymentEventListenerException if an error occurred when calling
36 | */
37 | void appDeploymentEvent(App app) throws AppDeploymentEventListenerException;
38 |
39 | /**
40 | * Invoked when an app is undeployed.
41 | *
42 | * @param appName name of the undeploying app.
43 | * @throws AppDeploymentEventListenerException if an error occurred when calling
44 | */
45 | void appUndeploymentEvent(String appName) throws AppDeploymentEventListenerException;
46 | }
47 |
--------------------------------------------------------------------------------
/components/org.wso2.carbon.uiserver/src/main/java/org/wso2/carbon/uiserver/internal/io/util/PathUtils.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
3 | *
4 | * WSO2 Inc. licenses this file to you under the Apache License,
5 | * Version 2.0 (the "License"); you may not use this file except
6 | * in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing,
12 | * software distributed under the License is distributed on an
13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 | * KIND, either express or implied. See the License for the
15 | * specific language governing permissions and limitations
16 | * under the License.
17 | */
18 |
19 | package org.wso2.carbon.uiserver.internal.io.util;
20 |
21 | import org.apache.commons.io.FilenameUtils;
22 |
23 | import java.nio.file.Path;
24 |
25 | /**
26 | * Utility methods for {@link Path}s.
27 | *
28 | * @since 0.8.0
29 | */
30 | public class PathUtils {
31 |
32 | private PathUtils() {
33 | }
34 |
35 | /**
36 | * Returns the file name of the given path.
37 | *
38 | * @param path file/directory path
39 | * @return file name (never {@code null})
40 | */
41 | public static String getName(Path path) {
42 | Path fileName = path.getFileName();
43 | return (fileName == null) ? "" : fileName.toString();
44 | }
45 |
46 | /**
47 | * Returns the file extension of the given path.
48 | *
49 | * @param filePath file path
50 | * @return file extension (never {@code null})
51 | */
52 | public static String getExtension(Path filePath) {
53 | return FilenameUtils.getExtension(filePath.getFileName().toString());
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/components/org.wso2.carbon.uiserver/src/main/java/org/wso2/carbon/uiserver/internal/impl/HtmlPage.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
3 | *
4 | * WSO2 Inc. licenses this file to you under the Apache License,
5 | * Version 2.0 (the "License"); you may not use this file except
6 | * in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing,
12 | * software distributed under the License is distributed on an
13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 | * KIND, either express or implied. See the License for the
15 | * specific language governing permissions and limitations
16 | * under the License.
17 | */
18 |
19 | package org.wso2.carbon.uiserver.internal.impl;
20 |
21 | import org.wso2.carbon.uiserver.api.Configuration;
22 | import org.wso2.carbon.uiserver.api.Page;
23 | import org.wso2.carbon.uiserver.api.UriPatten;
24 | import org.wso2.carbon.uiserver.api.exception.RenderingException;
25 | import org.wso2.carbon.uiserver.api.http.HttpRequest;
26 |
27 | /**
28 | * Page based on a HTML file.
29 | *
30 | * @since 0.10.3
31 | */
32 | public class HtmlPage extends Page {
33 |
34 | private final String content;
35 |
36 | /**
37 | * Creates a new page that renders given HTML content
38 | *
39 | * @param uriPatten URI pattern of the page
40 | * @param content HTML content of the page
41 | */
42 | public HtmlPage(UriPatten uriPatten, String content) {
43 | super(uriPatten);
44 | this.content = content;
45 | }
46 |
47 | @Override
48 | public String render(HttpRequest request, Configuration configuration) throws RenderingException {
49 | return content;
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/components/org.wso2.carbon.uiserver/src/test/java/org/wso2/carbon/uiserver/internal/io/util/PathUtilsTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
3 | *
4 | * WSO2 Inc. licenses this file to you under the Apache License,
5 | * Version 2.0 (the "License"); you may not use this file except
6 | * in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing,
12 | * software distributed under the License is distributed on an
13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 | * KIND, either express or implied. See the License for the
15 | * specific language governing permissions and limitations
16 | * under the License.
17 | */
18 |
19 | package org.wso2.carbon.uiserver.internal.io.util;
20 |
21 | import org.testng.Assert;
22 | import org.testng.annotations.Test;
23 |
24 | import java.nio.file.Path;
25 | import java.nio.file.Paths;
26 |
27 | import static org.mockito.Mockito.mock;
28 | import static org.mockito.Mockito.when;
29 |
30 | /**
31 | * Test cases for {@link PathUtils} class.
32 | *
33 | * @since 0.12.5
34 | */
35 | public class PathUtilsTest {
36 |
37 | @Test
38 | public void testGetNameReturnsEmptyString() {
39 | Path filePath = mock(Path.class);
40 | when(filePath.getFileName()).thenReturn(null);
41 | Assert.assertEquals(PathUtils.getName(filePath), "");
42 | }
43 |
44 | @Test
45 | public void testGetName() {
46 | Path filePath = Paths.get("test/some-file.txt");
47 | Assert.assertEquals(PathUtils.getName(filePath), "some-file.txt");
48 | }
49 |
50 | @Test
51 | public void testGetExtension() {
52 | Path filePath = Paths.get("test/some-file.txt");
53 | Assert.assertEquals(PathUtils.getExtension(filePath), "txt");
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/components/org.wso2.carbon.uiserver/src/main/java/org/wso2/carbon/uiserver/api/util/Multilocational.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
3 | *
4 | * WSO2 Inc. licenses this file to you under the Apache License,
5 | * Version 2.0 (the "License"); you may not use this file except
6 | * in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing,
12 | * software distributed under the License is distributed on an
13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 | * KIND, either express or implied. See the License for the
15 | * specific language governing permissions and limitations
16 | * under the License.
17 | */
18 |
19 | package org.wso2.carbon.uiserver.api.util;
20 |
21 | import java.util.List;
22 |
23 | /**
24 | * Represents an entity that can be present in more than one location.
25 | *
26 | * @since 0.12.0
27 | */
28 | public interface Multilocational {
29 |
30 | /**
31 | * Returns paths that the entity represented this object is present. First path of the returning list has the
32 | * highest priority and the last path has the least priority.
33 | *
34 | * @return paths that the entity represented this object is present
35 | */
36 | List getPaths();
37 |
38 | /**
39 | * Returns the path with the highest priority.
40 | *
41 | * @return highest priority path
42 | */
43 | default String getHighestPriorityPath() {
44 | return getPaths().get(0);
45 | }
46 |
47 | /**
48 | * Returns the path with the least priority.
49 | *
50 | * @return least priority path
51 | */
52 | default String getLeastPriorityPath() {
53 | List paths = getPaths();
54 | return paths.get(paths.size() - 1);
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/components/org.wso2.carbon.uiserver/src/main/java/org/wso2/carbon/uiserver/internal/impl/OverriddenTheme.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
3 | *
4 | * WSO2 Inc. licenses this file to you under the Apache License,
5 | * Version 2.0 (the "License"); you may not use this file except
6 | * in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing,
12 | * software distributed under the License is distributed on an
13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 | * KIND, either express or implied. See the License for the
15 | * specific language governing permissions and limitations
16 | * under the License.
17 | */
18 |
19 | package org.wso2.carbon.uiserver.internal.impl;
20 |
21 | import com.google.common.collect.ImmutableList;
22 | import org.wso2.carbon.uiserver.api.Theme;
23 |
24 | import java.util.Optional;
25 |
26 | /**
27 | * Represents an overridden theme.
28 | *
29 | * @since 0.12.0
30 | */
31 | public class OverriddenTheme extends Theme {
32 |
33 | private final Theme base;
34 | private final Theme override;
35 |
36 | /**
37 | * Creates a new overridden theme.
38 | *
39 | * @param base base theme
40 | * @param override theme that overrides the {@code base} theme
41 | */
42 | public OverriddenTheme(Theme base, Theme override) {
43 | super(override.getName(),
44 | ImmutableList.builder().addAll(override.getPaths()).addAll(base.getPaths()).build());
45 | this.base = base;
46 | this.override = override;
47 | }
48 |
49 | @Override
50 | public Theme getBase() {
51 | return base;
52 | }
53 |
54 | @Override
55 | public Optional getOverride() {
56 | return Optional.of(override);
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/components/org.wso2.carbon.uiserver/src/main/java/org/wso2/carbon/uiserver/api/exception/PageNotFoundException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
3 | *
4 | * WSO2 Inc. licenses this file to you under the Apache License,
5 | * Version 2.0 (the "License"); you may not use this file except
6 | * in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing,
12 | * software distributed under the License is distributed on an
13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 | * KIND, either express or implied. See the License for the
15 | * specific language governing permissions and limitations
16 | * under the License.
17 | */
18 |
19 | package org.wso2.carbon.uiserver.api.exception;
20 |
21 | import org.wso2.carbon.uiserver.api.http.HttpResponse;
22 |
23 | /**
24 | * Indicates a page not found error.
25 | *
26 | * @since 0.8.0
27 | */
28 | public class PageNotFoundException extends HttpErrorException {
29 |
30 | /**
31 | * Constructs a new exception with {@code null} as its detail message.
32 | */
33 | public PageNotFoundException() {
34 | super(HttpResponse.STATUS_NOT_FOUND);
35 | }
36 |
37 | /**
38 | * Constructs a new exception with the specified detail message.
39 | *
40 | * @param message detail message
41 | */
42 | public PageNotFoundException(String message) {
43 | super(HttpResponse.STATUS_NOT_FOUND, message);
44 | }
45 |
46 | /**
47 | * Constructs a new exception with the specified detail message and cause.
48 | *
49 | * @param message details message
50 | * @param cause the cause of the exception
51 | */
52 | public PageNotFoundException(String message, Throwable cause) {
53 | super(HttpResponse.STATUS_NOT_FOUND, message, cause);
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/components/org.wso2.carbon.uiserver/src/main/java/org/wso2/carbon/uiserver/internal/reference/ExtensionReference.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
3 | *
4 | * WSO2 Inc. licenses this file to you under the Apache License,
5 | * Version 2.0 (the "License"); you may not use this file except
6 | * in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing,
12 | * software distributed under the License is distributed on an
13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 | * KIND, either express or implied. See the License for the
15 | * specific language governing permissions and limitations
16 | * under the License.
17 | */
18 |
19 | package org.wso2.carbon.uiserver.internal.reference;
20 |
21 | import org.wso2.carbon.uiserver.internal.exception.FileOperationException;
22 |
23 | /**
24 | * A reference to an extension in a web app.
25 | *
26 | * @since 0.8.0
27 | */
28 | public interface ExtensionReference {
29 |
30 | /**
31 | * Returns the name of the extension represented by this reference.
32 | *
33 | * @return name of the extension
34 | * @throws FileOperationException if cannot read extension name
35 | */
36 | String getName() throws FileOperationException;
37 |
38 | /**
39 | * Returns the type of the extension represented by this reference.
40 | *
41 | * @return type of the extension
42 | * @throws FileOperationException if cannot read extension type
43 | */
44 | String getType() throws FileOperationException;
45 |
46 | /**
47 | * Returns the absolute path to the extension represented by this reference.
48 | *
49 | * @return absolute path to the extension
50 | * @throws FileOperationException if cannot obtain the path
51 | */
52 | String getPath() throws FileOperationException;
53 | }
54 |
--------------------------------------------------------------------------------
/components/org.wso2.carbon.uiserver/src/main/java/org/wso2/carbon/uiserver/internal/io/reference/ArtifactThemeReference.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
3 | *
4 | * WSO2 Inc. licenses this file to you under the Apache License,
5 | * Version 2.0 (the "License"); you may not use this file except
6 | * in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing,
12 | * software distributed under the License is distributed on an
13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 | * KIND, either express or implied. See the License for the
15 | * specific language governing permissions and limitations
16 | * under the License.
17 | */
18 |
19 | package org.wso2.carbon.uiserver.internal.io.reference;
20 |
21 | import org.wso2.carbon.uiserver.internal.exception.FileOperationException;
22 | import org.wso2.carbon.uiserver.internal.io.util.PathUtils;
23 | import org.wso2.carbon.uiserver.internal.reference.ThemeReference;
24 |
25 | import java.nio.file.Path;
26 |
27 | /**
28 | * A reference to a theme in a directory inside a web app artifact.
29 | *
30 | * @since 0.8.0
31 | */
32 | public class ArtifactThemeReference implements ThemeReference {
33 |
34 | private final Path themeDirectory;
35 |
36 | /**
37 | * Creates a reference to the theme which resides in the specified directory.
38 | *
39 | * @param themeDirectory directory that contains the theme
40 | */
41 | public ArtifactThemeReference(Path themeDirectory) {
42 | this.themeDirectory = themeDirectory;
43 | }
44 |
45 | @Override
46 | public String getName() throws FileOperationException {
47 | return PathUtils.getName(themeDirectory);
48 | }
49 |
50 | @Override
51 | public String getPath() throws FileOperationException {
52 | return themeDirectory.toString();
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/components/org.wso2.carbon.uiserver/src/main/java/org/wso2/carbon/uiserver/internal/impl/OverriddenExtension.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
3 | *
4 | * WSO2 Inc. licenses this file to you under the Apache License,
5 | * Version 2.0 (the "License"); you may not use this file except
6 | * in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing,
12 | * software distributed under the License is distributed on an
13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 | * KIND, either express or implied. See the License for the
15 | * specific language governing permissions and limitations
16 | * under the License.
17 | */
18 |
19 | package org.wso2.carbon.uiserver.internal.impl;
20 |
21 | import com.google.common.collect.ImmutableList;
22 | import org.wso2.carbon.uiserver.api.Extension;
23 |
24 | import java.util.Optional;
25 |
26 | /**
27 | * Represents an overridden extension.
28 | *
29 | * @since 0.12.0
30 | */
31 | public class OverriddenExtension extends Extension {
32 |
33 | private final Extension base;
34 | private final Extension override;
35 |
36 | /**
37 | * Creates a new overridden extension.
38 | *
39 | * @param base base extension
40 | * @param override extension that overrides the {@code base} extension
41 | */
42 | public OverriddenExtension(Extension base, Extension override) {
43 | super(override.getName(), override.getType(),
44 | ImmutableList.builder().addAll(override.getPaths()).addAll(base.getPaths()).build());
45 | this.base = base;
46 | this.override = override;
47 | }
48 |
49 | @Override
50 | public Extension getBase() {
51 | return base;
52 | }
53 |
54 | @Override
55 | public Optional getOverride() {
56 | return Optional.of(override);
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/components/org.wso2.carbon.uiserver/src/test/java/org/wso2/carbon/uiserver/internal/deployment/AppCreatorTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
3 | *
4 | * WSO2 Inc. licenses this file to you under the Apache License,
5 | * Version 2.0 (the "License"); you may not use this file except
6 | * in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing,
12 | * software distributed under the License is distributed on an
13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 | * KIND, either express or implied. See the License for the
15 | * specific language governing permissions and limitations
16 | * under the License.
17 | */
18 |
19 | package org.wso2.carbon.uiserver.internal.deployment;
20 |
21 | import org.testng.Assert;
22 | import org.testng.annotations.DataProvider;
23 | import org.testng.annotations.Test;
24 | import org.wso2.carbon.uiserver.api.App;
25 | import org.wso2.carbon.uiserver.internal.io.reference.ArtifactAppReference;
26 | import org.wso2.carbon.uiserver.internal.reference.AppReference;
27 |
28 | import java.nio.file.Paths;
29 |
30 | /**
31 | * Test cases for {@link AppCreator} class.
32 | *
33 | * @since 0.12.5
34 | */
35 | public class AppCreatorTest {
36 |
37 | @DataProvider
38 | public Object[][] appReferences() {
39 | return new Object[][]{
40 | {new ArtifactAppReference(Paths.get("src/test/resources/apps/full-app/"))},
41 | {new ArtifactAppReference(Paths.get("src/test/resources/apps/minimal-app/"))},
42 | {new ArtifactAppReference(Paths.get("src/test/resources/apps/empty-app/"))}
43 | };
44 | }
45 |
46 | @Test(dataProvider = "appReferences")
47 | public void testCreateApp(AppReference appReference) {
48 | App app = AppCreator.createApp(appReference, "/test");
49 | Assert.assertNotNull(app);
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/components/org.wso2.carbon.uiserver/src/main/java/org/wso2/carbon/uiserver/internal/exception/BadRequestException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
3 | *
4 | * WSO2 Inc. licenses this file to you under the Apache License,
5 | * Version 2.0 (the "License"); you may not use this file except
6 | * in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing,
12 | * software distributed under the License is distributed on an
13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 | * KIND, either express or implied. See the License for the
15 | * specific language governing permissions and limitations
16 | * under the License.
17 | */
18 |
19 | package org.wso2.carbon.uiserver.internal.exception;
20 |
21 | import org.wso2.carbon.uiserver.api.exception.HttpErrorException;
22 | import org.wso2.carbon.uiserver.api.http.HttpResponse;
23 |
24 | /**
25 | * Indicates a bad/invalid HTTP request.
26 | *
27 | * @since 0.13.4
28 | */
29 | public class BadRequestException extends HttpErrorException {
30 |
31 | /**
32 | * Constructs a new exception with {@code null} as its detail message.
33 | */
34 | public BadRequestException() {
35 | super(HttpResponse.STATUS_BAD_REQUEST);
36 | }
37 |
38 | /**
39 | * Constructs a new exception with the specified detail message.
40 | *
41 | * @param message detail message
42 | */
43 | public BadRequestException(String message) {
44 | super(HttpResponse.STATUS_BAD_REQUEST, message);
45 | }
46 |
47 | /**
48 | * Constructs a new exception with the specified detail message and cause.
49 | *
50 | * @param message details message
51 | * @param cause the cause of the exception
52 | */
53 | public BadRequestException(String message, Throwable cause) {
54 | super(HttpResponse.STATUS_BAD_REQUEST, message, cause);
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/components/org.wso2.carbon.uiserver/src/main/java/org/wso2/carbon/uiserver/internal/exception/ResourceNotFoundException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
3 | *
4 | * WSO2 Inc. licenses this file to you under the Apache License,
5 | * Version 2.0 (the "License"); you may not use this file except
6 | * in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing,
12 | * software distributed under the License is distributed on an
13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 | * KIND, either express or implied. See the License for the
15 | * specific language governing permissions and limitations
16 | * under the License.
17 | */
18 |
19 | package org.wso2.carbon.uiserver.internal.exception;
20 |
21 | import org.wso2.carbon.uiserver.api.exception.HttpErrorException;
22 | import org.wso2.carbon.uiserver.api.http.HttpResponse;
23 |
24 | /**
25 | * Indicates a resource not found error.
26 | *
27 | * @since 0.8.0
28 | */
29 | public class ResourceNotFoundException extends HttpErrorException {
30 |
31 | /**
32 | * Constructs a new exception with {@code null} as its detail message.
33 | */
34 | public ResourceNotFoundException() {
35 | super(HttpResponse.STATUS_NOT_FOUND);
36 | }
37 |
38 | /**
39 | * Constructs a new exception with the specified detail message.
40 | *
41 | * @param message detail message
42 | */
43 | public ResourceNotFoundException(String message) {
44 | super(HttpResponse.STATUS_NOT_FOUND, message);
45 | }
46 |
47 | /**
48 | * Constructs a new exception with the specified detail message and cause.
49 | *
50 | * @param message details message
51 | * @param cause the cause of the exception
52 | */
53 | public ResourceNotFoundException(String message, Throwable cause) {
54 | super(HttpResponse.STATUS_NOT_FOUND, message, cause);
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/components/org.wso2.carbon.uiserver/src/main/java/org/wso2/carbon/uiserver/internal/deployment/listener/CarbonUiServer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
3 | *
4 | * WSO2 Inc. licenses this file to you under the Apache License,
5 | * Version 2.0 (the "License"); you may not use this file except
6 | * in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing,
12 | * software distributed under the License is distributed on an
13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 | * KIND, either express or implied. See the License for the
15 | * specific language governing permissions and limitations
16 | * under the License.
17 | */
18 |
19 | package org.wso2.carbon.uiserver.internal.deployment.listener;
20 |
21 | import org.wso2.carbon.uiserver.api.App;
22 | import org.wso2.carbon.uiserver.internal.deployment.AppDeploymentEventListener;
23 | import org.wso2.carbon.uiserver.spi.Server;
24 |
25 | import java.util.Optional;
26 | import java.util.concurrent.ConcurrentHashMap;
27 | import java.util.concurrent.ConcurrentMap;
28 |
29 | /**
30 | * Carbon UI server service component.
31 | *
32 | * @since 0.8.0
33 | */
34 | public class CarbonUiServer implements Server, AppDeploymentEventListener {
35 |
36 | /**
37 | * Contains deployed apps. Here key is the app name and value is the deployed app.
38 | */
39 | private final ConcurrentMap deployedApps = new ConcurrentHashMap<>();
40 |
41 | @Override
42 | public Optional getApp(String appName) {
43 | return Optional.ofNullable(deployedApps.get(appName));
44 | }
45 |
46 | @Override
47 | public void appDeploymentEvent(App app) {
48 | deployedApps.put(app.getName(), app);
49 | }
50 |
51 | @Override
52 | public void appUndeploymentEvent(String appName) {
53 | deployedApps.remove(appName);
54 | }
55 |
56 | public void close() {
57 | deployedApps.clear();
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/components/org.wso2.carbon.uiserver/src/main/java/org/wso2/carbon/uiserver/api/exception/PageRedirectException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
3 | *
4 | * WSO2 Inc. licenses this file to you under the Apache License,
5 | * Version 2.0 (the "License"); you may not use this file except
6 | * in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing,
12 | * software distributed under the License is distributed on an
13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 | * KIND, either express or implied. See the License for the
15 | * specific language governing permissions and limitations
16 | * under the License.
17 | */
18 |
19 | package org.wso2.carbon.uiserver.api.exception;
20 |
21 | import org.wso2.carbon.uiserver.api.http.HttpResponse;
22 |
23 | /**
24 | * Indicates a page redirection.
25 | *
26 | * @since 0.8.0
27 | */
28 | public class PageRedirectException extends HttpErrorException {
29 |
30 | private final String redirectUrl;
31 |
32 | /**
33 | * Constructs a new exception with the specified redirect URL.
34 | *
35 | * @param redirectUrl redirection URI or URL
36 | */
37 | public PageRedirectException(String redirectUrl) {
38 | super(HttpResponse.STATUS_FOUND, "Redirecting to '" + redirectUrl + "'.");
39 | this.redirectUrl = redirectUrl;
40 | }
41 |
42 | /**
43 | * Constructs a new exception with the specified redirect URL.
44 | *
45 | * @param redirectUrl redirection URI or URL
46 | * @param cause the cause of the exception
47 | */
48 | public PageRedirectException(String redirectUrl, Throwable cause) {
49 | super(HttpResponse.STATUS_FOUND, "Redirecting to '" + redirectUrl + "'.", cause);
50 | this.redirectUrl = redirectUrl;
51 | }
52 |
53 | /**
54 | * Returns the redirection URL of this exception.
55 | *
56 | * @return the redirection URL
57 | */
58 | public String getRedirectUrl() {
59 | return redirectUrl;
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/components/org.wso2.carbon.uiserver/src/main/java/org/wso2/carbon/uiserver/internal/io/reference/ArtifactExtensionReference.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
3 | *
4 | * WSO2 Inc. licenses this file to you under the Apache License,
5 | * Version 2.0 (the "License"); you may not use this file except
6 | * in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing,
12 | * software distributed under the License is distributed on an
13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 | * KIND, either express or implied. See the License for the
15 | * specific language governing permissions and limitations
16 | * under the License.
17 | */
18 |
19 | package org.wso2.carbon.uiserver.internal.io.reference;
20 |
21 | import org.wso2.carbon.uiserver.internal.exception.FileOperationException;
22 | import org.wso2.carbon.uiserver.internal.io.util.PathUtils;
23 | import org.wso2.carbon.uiserver.internal.reference.ExtensionReference;
24 |
25 | import java.nio.file.Path;
26 |
27 | /**
28 | * A reference to an extension in a directory inside a web app artifact.
29 | *
30 | * @since 0.8.0
31 | */
32 | public class ArtifactExtensionReference implements ExtensionReference {
33 |
34 | private final Path extensionDirectory;
35 |
36 | /**
37 | * Creates a reference to the extension which resides in the specified directory.
38 | *
39 | * @param extensionDirectory directory that contains the extension
40 | */
41 | public ArtifactExtensionReference(Path extensionDirectory) {
42 | this.extensionDirectory = extensionDirectory;
43 | }
44 |
45 | @Override
46 | public String getName() throws FileOperationException {
47 | return PathUtils.getName(extensionDirectory);
48 | }
49 |
50 | @Override
51 | public String getType() throws FileOperationException {
52 | return PathUtils.getName(extensionDirectory.getParent());
53 | }
54 |
55 | @Override
56 | public String getPath() throws FileOperationException {
57 | return extensionDirectory.toString();
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/components/org.wso2.carbon.uiserver/src/main/java/org/wso2/carbon/uiserver/internal/reference/FileReference.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
3 | *
4 | * WSO2 Inc. licenses this file to you under the Apache License,
5 | * Version 2.0 (the "License"); you may not use this file except
6 | * in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing,
12 | * software distributed under the License is distributed on an
13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 | * KIND, either express or implied. See the License for the
15 | * specific language governing permissions and limitations
16 | * under the License.
17 | */
18 |
19 | package org.wso2.carbon.uiserver.internal.reference;
20 |
21 | import org.wso2.carbon.uiserver.internal.exception.FileOperationException;
22 |
23 | /**
24 | * A reference to a file in a web app.
25 | *
26 | * @since 0.8.0
27 | */
28 | public interface FileReference {
29 |
30 | /**
31 | * Returns the name of the file represented by this reference.
32 | *
33 | * @return name of the file
34 | * @throws FileOperationException if cannot read file name
35 | */
36 | String getName() throws FileOperationException;
37 |
38 | /**
39 | * Returns the extension of the file represented by this reference.
40 | *
41 | * @return extension of the file
42 | * @throws FileOperationException if cannot read file extension
43 | */
44 | String getExtension() throws FileOperationException;
45 |
46 | /**
47 | * Returns the content of the file represented by this reference.
48 | *
49 | * @return content of the file
50 | * @throws FileOperationException if cannot read file content
51 | */
52 | String getContent() throws FileOperationException;
53 |
54 | /**
55 | * Returns the absolute path to the file represented by this reference.
56 | *
57 | * @return absolute path to the file
58 | * @throws FileOperationException if cannot obtain the path
59 | */
60 | String getFilePath() throws FileOperationException;
61 | }
62 |
--------------------------------------------------------------------------------
/components/org.wso2.carbon.uiserver/src/test/java/org/wso2/carbon/uiserver/internal/deployment/listener/CarbonUiServerTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
3 | *
4 | * WSO2 Inc. licenses this file to you under the Apache License,
5 | * Version 2.0 (the "License"); you may not use this file except
6 | * in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing,
12 | * software distributed under the License is distributed on an
13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 | * KIND, either express or implied. See the License for the
15 | * specific language governing permissions and limitations
16 | * under the License.
17 | */
18 |
19 | package org.wso2.carbon.uiserver.internal.deployment.listener;
20 |
21 | import org.testng.Assert;
22 | import org.testng.annotations.Test;
23 | import org.wso2.carbon.uiserver.api.App;
24 |
25 | import static org.mockito.Mockito.mock;
26 | import static org.mockito.Mockito.when;
27 |
28 | /**
29 | * Test cases for {@link CarbonUiServer} class.
30 | *
31 | * @since 0.15.0
32 | */
33 | public class CarbonUiServerTest {
34 |
35 | @Test
36 | public void testGetApp() {
37 | CarbonUiServer carbonUiServer = new CarbonUiServer();
38 |
39 | carbonUiServer.appDeploymentEvent(createApp("foo"));
40 | Assert.assertTrue(carbonUiServer.getApp("foo").isPresent());
41 |
42 | Assert.assertFalse(carbonUiServer.getApp("bar").isPresent());
43 | carbonUiServer.appDeploymentEvent(createApp("bar"));
44 | Assert.assertTrue(carbonUiServer.getApp("bar").isPresent());
45 |
46 | carbonUiServer.appUndeploymentEvent("foo");
47 | Assert.assertFalse(carbonUiServer.getApp("foo").isPresent());
48 | Assert.assertTrue(carbonUiServer.getApp("bar").isPresent());
49 |
50 | carbonUiServer.close();
51 | Assert.assertFalse(carbonUiServer.getApp("foo").isPresent());
52 | Assert.assertFalse(carbonUiServer.getApp("bar").isPresent());
53 | }
54 |
55 | private static App createApp(String appName) {
56 | App app = mock(App.class);
57 | when(app.getName()).thenReturn(appName);
58 | return app;
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/components/org.wso2.carbon.uiserver/src/test/java/org/wso2/carbon/uiserver/api/ConfigurationTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
3 | *
4 | * WSO2 Inc. licenses this file to you under the Apache License,
5 | * Version 2.0 (the "License"); you may not use this file except
6 | * in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing,
12 | * software distributed under the License is distributed on an
13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 | * KIND, either express or implied. See the License for the
15 | * specific language governing permissions and limitations
16 | * under the License.
17 | */
18 |
19 | package org.wso2.carbon.uiserver.api;
20 |
21 | import org.testng.Assert;
22 | import org.testng.annotations.Test;
23 |
24 | import java.util.Map;
25 |
26 | import static org.wso2.carbon.uiserver.api.http.HttpResponse.HEADER_CACHE_CONTROL;
27 | import static org.wso2.carbon.uiserver.api.http.HttpResponse.HEADER_EXPIRES;
28 | import static org.wso2.carbon.uiserver.api.http.HttpResponse.HEADER_PRAGMA;
29 |
30 | import static java.util.Collections.singletonMap;
31 |
32 | /**
33 | * Test cases for {@link Configuration} class.
34 | *
35 | * @since 0.12.5
36 | */
37 | public class ConfigurationTest {
38 |
39 | @Test
40 | public void testGetResponseHeaders() {
41 | Map pages = singletonMap(HEADER_EXPIRES, "100");
42 | Map staticResources = singletonMap(HEADER_CACHE_CONTROL, "public,max-age=100");
43 | Configuration configuration = new Configuration(new Configuration.HttpResponseHeaders(pages, staticResources));
44 |
45 | Assert.assertEquals(configuration.getResponseHeaders().forPages().get(HEADER_PRAGMA),
46 | Configuration.DEFAULT_CONFIGURATION.getResponseHeaders().forPages().get(HEADER_PRAGMA));
47 | Assert.assertEquals(configuration.getResponseHeaders().forPages().get(HEADER_EXPIRES),
48 | pages.get(HEADER_EXPIRES));
49 | Assert.assertEquals(configuration.getResponseHeaders().forStaticResources().get(HEADER_CACHE_CONTROL),
50 | staticResources.get(HEADER_CACHE_CONTROL));
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/tests/distribution/carbon-home/conf/default/deployment.yaml:
--------------------------------------------------------------------------------
1 | # Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the \"License\");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an \"AS IS\" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | # Carbon Configuration Parameters
16 | wso2.carbon:
17 | # value to uniquely identify a server
18 | id: carbon-kernel
19 | # server name
20 | name: WSO2 Carbon Kernel
21 | # ports used by this server
22 | ports:
23 | # port offset
24 | offset: 0
25 |
26 | wso2.securevault:
27 | secretRepository:
28 | type: org.wso2.carbon.secvault.repository.DefaultSecretRepository
29 | parameters:
30 | privateKeyAlias: wso2carbon
31 | keystoreLocation: ${sys:carbon.home}/resources/security/securevault.jks
32 | secretPropertiesFile: ${sys:carbon.home}/conf/${sys:wso2.runtime}/secrets.properties
33 | masterKeyReader:
34 | type: org.wso2.carbon.secvault.reader.DefaultMasterKeyReader
35 | parameters:
36 | masterKeyReaderFile: ${sys:carbon.home}/conf/${sys:wso2.runtime}/master-keys.yaml
37 |
38 | wso2.transport.http:
39 | transportProperties:
40 | - name: "server.bootstrap.socket.timeout"
41 | value: 60
42 | - name: "client.bootstrap.socket.timeout"
43 | value: 60
44 | - name: "latency.metrics.enabled"
45 | value: true
46 |
47 | listenerConfigurations:
48 | - id: "default-http"
49 | host: "0.0.0.0"
50 | port: 9090
51 |
52 | - id: "for-test-app"
53 | host: "0.0.0.0"
54 | port: 9443
55 | scheme: https
56 | keyStoreFile: "${carbon.home}/resources/security/wso2carbon.jks"
57 | keyStorePassword: wso2carbon
58 | certPass: wso2carbon
59 |
60 | senderConfigurations:
61 | - id: "default-http-sender"
62 |
63 | wso2.carbon-ui-server:
64 | apps:
65 | "test":
66 | contextPath: "/sample"
67 | transportId: "for-test-app"
68 |
--------------------------------------------------------------------------------
/components/org.wso2.carbon.uiserver/src/main/java/org/wso2/carbon/uiserver/internal/io/reference/ArtifactPageReference.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
3 | *
4 | * WSO2 Inc. licenses this file to you under the Apache License,
5 | * Version 2.0 (the "License"); you may not use this file except
6 | * in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing,
12 | * software distributed under the License is distributed on an
13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 | * KIND, either express or implied. See the License for the
15 | * specific language governing permissions and limitations
16 | * under the License.
17 | */
18 |
19 | package org.wso2.carbon.uiserver.internal.io.reference;
20 |
21 | import org.apache.commons.io.FilenameUtils;
22 | import org.wso2.carbon.uiserver.internal.exception.FileOperationException;
23 | import org.wso2.carbon.uiserver.internal.reference.FileReference;
24 | import org.wso2.carbon.uiserver.internal.reference.PageReference;
25 |
26 | import java.nio.file.Path;
27 |
28 | /**
29 | * A reference to a page inside a web app artifact.
30 | *
31 | * @since 0.8.0
32 | */
33 | public class ArtifactPageReference implements PageReference {
34 |
35 | private final Path pageFile;
36 | private final ArtifactAppReference appReference;
37 |
38 | /**
39 | * Creates a reference to the page specified by the path.
40 | *
41 | * @param pageFile path to the page
42 | * @param appReference reference to the belonging app
43 | */
44 | public ArtifactPageReference(Path pageFile, ArtifactAppReference appReference) {
45 | this.pageFile = pageFile;
46 | this.appReference = appReference;
47 | }
48 |
49 | @Override
50 | public String getPathPattern() throws FileOperationException {
51 | StringBuilder sb = new StringBuilder();
52 | Path pagesDirectory = appReference.getPagesDirectory().relativize(pageFile);
53 | for (Path path : pagesDirectory) {
54 | sb.append('/').append(FilenameUtils.removeExtension(path.toString()));
55 | }
56 | return sb.toString();
57 | }
58 |
59 | @Override
60 | public FileReference getHtmlFile() {
61 | return new ArtifactFileReference(pageFile);
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/components/org.wso2.carbon.uiserver/src/main/java/org/wso2/carbon/uiserver/api/exception/UiServerException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
3 | *
4 | * WSO2 Inc. licenses this file to you under the Apache License,
5 | * Version 2.0 (the "License"); you may not use this file except
6 | * in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing,
12 | * software distributed under the License is distributed on an
13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 | * KIND, either express or implied. See the License for the
15 | * specific language governing permissions and limitations
16 | * under the License.
17 | */
18 |
19 | package org.wso2.carbon.uiserver.api.exception;
20 |
21 | /**
22 | * Indicates a generic exception occurred in Carbon UI Server.
23 | *
24 | * @since 0.8.0
25 | */
26 | public class UiServerException extends Exception {
27 |
28 | /**
29 | * Constructs a new exception with {@code null} as its detail message. The cause is not initialized, and may
30 | * subsequently be initialized by a call to {@link #initCause(Throwable)}.
31 | */
32 | public UiServerException() {
33 | }
34 |
35 | /**
36 | * Constructs a new exception with the specified detail message. The cause is not initialized, and may
37 | * subsequently be initialized by a call to {@link #initCause}.
38 | *
39 | * @param message the detail message of the exception
40 | */
41 | public UiServerException(String message) {
42 | super(message);
43 | }
44 |
45 | /**
46 | * Constructs a new exception with the specified cause and a detail message of {@code (cause==null ? null :
47 | * cause.toString())} which typically contains the class and detail message of the {@code cause}.
48 | *
49 | * @param cause the cause of the exception
50 | */
51 | public UiServerException(Throwable cause) {
52 | super(cause);
53 | }
54 |
55 | /**
56 | * Constructs a new exception with the specified detail message and cause.
57 | *
58 | * @param message the detail message of the exception
59 | * @param cause the cause of the exception
60 | */
61 | public UiServerException(String message, Throwable cause) {
62 | super(message, cause);
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/components/org.wso2.carbon.uiserver/src/main/java/org/wso2/carbon/uiserver/api/exception/RenderingException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
3 | *
4 | * WSO2 Inc. licenses this file to you under the Apache License,
5 | * Version 2.0 (the "License"); you may not use this file except
6 | * in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing,
12 | * software distributed under the License is distributed on an
13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 | * KIND, either express or implied. See the License for the
15 | * specific language governing permissions and limitations
16 | * under the License.
17 | */
18 |
19 | package org.wso2.carbon.uiserver.api.exception;
20 |
21 | /**
22 | * Indicates an error occurred when rendering a page.
23 | *
24 | * @since 0.8.0
25 | */
26 | public class RenderingException extends UiServerRuntimeException {
27 |
28 | /**
29 | * Constructs a new exception with {@code null} as its detail message. The cause is not initialized, and may
30 | * subsequently be initialized by a call to {@link #initCause(Throwable)}.
31 | */
32 | public RenderingException() {
33 | }
34 |
35 | /**
36 | * Constructs a new exception with the specified detail message. The cause is not initialized, and may subsequently
37 | * be initialized by a call to {@link #initCause}.
38 | *
39 | * @param message the detail message of the exception
40 | */
41 | public RenderingException(String message) {
42 | super(message);
43 | }
44 |
45 | /**
46 | * Constructs a new exception with the specified cause and a detail message of {@code (cause==null ? null :
47 | * cause.toString())} which typically contains the class and detail message of the {@code cause}.
48 | *
49 | * @param cause the cause of the exception
50 | */
51 | public RenderingException(Throwable cause) {
52 | super(cause);
53 | }
54 |
55 | /**
56 | * Constructs a new exception with the specified detail message and cause.
57 | *
58 | * @param message the detail message of the exception
59 | * @param cause the cause of the exception
60 | */
61 | public RenderingException(String message, Throwable cause) {
62 | super(message, cause);
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/tests/distribution/src/assembly/bin.xml:
--------------------------------------------------------------------------------
1 |
18 |
19 |
20 | carbon-ui-server
21 |
22 | true
23 | wso2-cuis-${project.version}
24 |
25 |
26 | zip
27 |
28 |
29 |
30 |
31 | target/wso2carbon-kernel-${carbon.kernel.version}
32 | .
33 | 644
34 |
35 | **/*.lock
36 | **/.data
37 | **/.settings
38 | libcairo-swt.so
39 | eclipse
40 | **/*.sh
41 | **/native/*
42 |
43 |
44 |
45 |
46 | target/wso2carbon-kernel-${carbon.kernel.version}
47 | .
48 |
49 | **/*.sh
50 | **/native/*
51 |
52 | 755
53 |
54 |
55 |
56 | carbon-home
57 | .
58 |
59 | **/*.ipr
60 | **/*.iwr
61 | **/*.eclipse
62 |
63 | 644
64 |
65 |
66 |
67 |
68 |
--------------------------------------------------------------------------------
/components/org.wso2.carbon.uiserver/src/main/java/org/wso2/carbon/uiserver/api/exception/UiServerRuntimeException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
3 | *
4 | * WSO2 Inc. licenses this file to you under the Apache License,
5 | * Version 2.0 (the "License"); you may not use this file except
6 | * in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing,
12 | * software distributed under the License is distributed on an
13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 | * KIND, either express or implied. See the License for the
15 | * specific language governing permissions and limitations
16 | * under the License.
17 | */
18 |
19 | package org.wso2.carbon.uiserver.api.exception;
20 |
21 | /**
22 | * Indicates a generic runtime exception occurred in Carbon UI Server.
23 | *
24 | * @since 0.8.0
25 | */
26 | public class UiServerRuntimeException extends RuntimeException {
27 |
28 | /**
29 | * Constructs a new exception with {@code null} as its detail message. The cause is not initialized, and may
30 | * subsequently be initialized by a call to {@link #initCause(Throwable)}.
31 | */
32 | public UiServerRuntimeException() {
33 | }
34 |
35 | /**
36 | * Constructs a new exception with the specified detail message. The cause is not initialized, and may
37 | * subsequently be initialized by a call to {@link #initCause}.
38 | *
39 | * @param message the detail message of the exception
40 | */
41 | public UiServerRuntimeException(String message) {
42 | super(message);
43 | }
44 |
45 | /**
46 | * Constructs a new exception with the specified cause and a detail message of {@code (cause==null ? null :
47 | * cause.toString())} which typically contains the class and detail message of the {@code cause}.
48 | *
49 | * @param cause the cause of the exception
50 | */
51 | public UiServerRuntimeException(Throwable cause) {
52 | super(cause);
53 | }
54 |
55 | /**
56 | * Constructs a new exception with the specified detail message and cause.
57 | *
58 | * @param message the detail message of the exception
59 | * @param cause the cause of the exception
60 | */
61 | public UiServerRuntimeException(String message, Throwable cause) {
62 | super(message, cause);
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/components/org.wso2.carbon.uiserver/src/test/java/org/wso2/carbon/uiserver/internal/deployment/msf4j/MicroserviceRegistrationTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
3 | *
4 | * WSO2 Inc. licenses this file to you under the Apache License,
5 | * Version 2.0 (the "License"); you may not use this file except
6 | * in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing,
12 | * software distributed under the License is distributed on an
13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 | * KIND, either express or implied. See the License for the
15 | * specific language governing permissions and limitations
16 | * under the License.
17 | */
18 |
19 | package org.wso2.carbon.uiserver.internal.deployment.msf4j;
20 |
21 | import org.osgi.framework.ServiceRegistration;
22 | import org.testng.Assert;
23 | import org.testng.annotations.Test;
24 | import org.wso2.carbon.uiserver.internal.http.HttpTransport;
25 |
26 | import static org.mockito.Mockito.mock;
27 | import static org.mockito.Mockito.verify;
28 |
29 | /**
30 | * Test cases for {@link MicroserviceRegistration} class.
31 | *
32 | * @since 0.15.0
33 | */
34 | public class MicroserviceRegistrationTest {
35 |
36 | @Test
37 | @SuppressWarnings("unchecked")
38 | public void testGetRegisteredHttpTransport() {
39 | HttpTransport httpTransport = createHttpTransport();
40 | ServiceRegistration serviceRegistration = mock(ServiceRegistration.class);
41 | MicroserviceRegistration microserviceRegistration = new MicroserviceRegistration(httpTransport,
42 | serviceRegistration);
43 |
44 | Assert.assertEquals(microserviceRegistration.getRegisteredHttpTransport(), httpTransport);
45 | }
46 |
47 | @Test
48 | @SuppressWarnings("unchecked")
49 | public void testUnregister() {
50 | HttpTransport httpTransport = createHttpTransport();
51 | ServiceRegistration serviceRegistration = mock(ServiceRegistration.class);
52 | new MicroserviceRegistration(httpTransport, serviceRegistration).unregister();
53 |
54 | verify(serviceRegistration).unregister();
55 | }
56 |
57 | private static HttpTransport createHttpTransport() {
58 | return new HttpTransport("foo", "bar", "http", "localhost", 9292);
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/components/org.wso2.carbon.uiserver/src/main/java/org/wso2/carbon/uiserver/internal/exception/ConfigurationException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
3 | *
4 | * WSO2 Inc. licenses this file to you under the Apache License,
5 | * Version 2.0 (the "License"); you may not use this file except
6 | * in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing,
12 | * software distributed under the License is distributed on an
13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 | * KIND, either express or implied. See the License for the
15 | * specific language governing permissions and limitations
16 | * under the License.
17 | */
18 |
19 | package org.wso2.carbon.uiserver.internal.exception;
20 |
21 | /**
22 | * Indicates an error happens when reading or parsing or loading or processing configuration.
23 | *
24 | * @since 0.12.1
25 | */
26 | public class ConfigurationException extends AppCreationException {
27 |
28 | /**
29 | * Constructs a new exception with {@code null} as its detail message. The cause is not initialized, and may
30 | * subsequently be initialized by a call to {@link #initCause(Throwable)}.
31 | */
32 | public ConfigurationException() {
33 | }
34 |
35 | /**
36 | * Constructs a new exception with the specified detail message. The cause is not initialized, and may subsequently
37 | * be initialized by a call to {@link #initCause}.
38 | *
39 | * @param message the detail message of the exception
40 | */
41 | public ConfigurationException(String message) {
42 | super(message);
43 | }
44 |
45 | /**
46 | * Constructs a new exception with the specified cause and a detail message of {@code (cause==null ? null :
47 | * cause.toString())} which typically contains the class and detail message of the {@code cause}.
48 | *
49 | * @param cause the cause of the exception
50 | */
51 | public ConfigurationException(Throwable cause) {
52 | super(cause);
53 | }
54 |
55 | /**
56 | * Constructs a new exception with the specified detail message and cause.
57 | *
58 | * @param message the detail message of the exception
59 | * @param cause the cause of the exception
60 | */
61 | public ConfigurationException(String message, Throwable cause) {
62 | super(message, cause);
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/components/org.wso2.carbon.uiserver/src/main/java/org/wso2/carbon/uiserver/internal/io/reference/ArtifactFileReference.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
3 | *
4 | * WSO2 Inc. licenses this file to you under the Apache License,
5 | * Version 2.0 (the "License"); you may not use this file except
6 | * in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing,
12 | * software distributed under the License is distributed on an
13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 | * KIND, either express or implied. See the License for the
15 | * specific language governing permissions and limitations
16 | * under the License.
17 | */
18 |
19 | package org.wso2.carbon.uiserver.internal.io.reference;
20 |
21 | import org.wso2.carbon.uiserver.internal.exception.FileOperationException;
22 | import org.wso2.carbon.uiserver.internal.io.util.PathUtils;
23 | import org.wso2.carbon.uiserver.internal.reference.FileReference;
24 |
25 | import java.io.IOException;
26 | import java.nio.charset.StandardCharsets;
27 | import java.nio.file.Files;
28 | import java.nio.file.Path;
29 |
30 | /**
31 | * A reference to a file inside a web app artifact..
32 | *
33 | * @since 0.8.0
34 | */
35 | public class ArtifactFileReference implements FileReference {
36 |
37 | private final Path filePath;
38 |
39 | /**
40 | * Creates a reference to the file specified by the path.
41 | *
42 | * @param filePath path to the file
43 | */
44 | public ArtifactFileReference(Path filePath) {
45 | this.filePath = filePath;
46 | }
47 |
48 | @Override
49 | public String getName() throws FileOperationException {
50 | return PathUtils.getName(filePath);
51 | }
52 |
53 | @Override
54 | public String getExtension() throws FileOperationException {
55 | return PathUtils.getExtension(filePath);
56 | }
57 |
58 | @Override
59 | public String getContent() throws FileOperationException {
60 | try {
61 | return new String(Files.readAllBytes(filePath), StandardCharsets.UTF_8);
62 | } catch (IOException e) {
63 | throw new FileOperationException("Cannot read content of file '" + filePath + "'.", e);
64 | }
65 | }
66 |
67 | @Override
68 | public String getFilePath() throws FileOperationException {
69 | return filePath.toString();
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/components/org.wso2.carbon.uiserver/src/main/java/org/wso2/carbon/uiserver/api/exception/HttpErrorException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
3 | *
4 | * WSO2 Inc. licenses this file to you under the Apache License,
5 | * Version 2.0 (the "License"); you may not use this file except
6 | * in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing,
12 | * software distributed under the License is distributed on an
13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 | * KIND, either express or implied. See the License for the
15 | * specific language governing permissions and limitations
16 | * under the License.
17 | */
18 |
19 | package org.wso2.carbon.uiserver.api.exception;
20 |
21 | /**
22 | * Indicates a HTTP error.
23 | *
24 | * @since 0.8.0
25 | */
26 | public class HttpErrorException extends UiServerRuntimeException {
27 |
28 | private final int httpStatusCode;
29 |
30 | /**
31 | * Constructs a new exception with the specified HTTP status code and {@code null} as its detail message.
32 | *
33 | * @param httpStatusCode HTTP error status code
34 | */
35 | public HttpErrorException(int httpStatusCode) {
36 | this.httpStatusCode = httpStatusCode;
37 | }
38 |
39 | /**
40 | * Constructs a new exception with the specified HTTP status code and detail message.
41 | *
42 | * @param httpStatusCode HTTP error status code
43 | * @param message detail message
44 | */
45 | public HttpErrorException(int httpStatusCode, String message) {
46 | super(message);
47 | this.httpStatusCode = httpStatusCode;
48 | }
49 |
50 | /**
51 | * Constructs a new exception with the specified HTTP status code, detail message, and cause.
52 | *
53 | * @param httpStatusCode HTTP error status code
54 | * @param message detail message
55 | * @param cause the cause of the exception
56 | */
57 | public HttpErrorException(int httpStatusCode, String message, Throwable cause) {
58 | super(message, cause);
59 | this.httpStatusCode = httpStatusCode;
60 | }
61 |
62 | /**
63 | * Returns the HTTP status error code of this HTTP exception.
64 | *
65 | * @return HTTP status code of the HTTP exception
66 | */
67 | public int getHttpStatusCode() {
68 | return this.httpStatusCode;
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/components/org.wso2.carbon.uiserver/src/test/java/org/wso2/carbon/uiserver/api/ThemeTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
3 | *
4 | * WSO2 Inc. licenses this file to you under the Apache License,
5 | * Version 2.0 (the "License"); you may not use this file except
6 | * in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing,
12 | * software distributed under the License is distributed on an
13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 | * KIND, either express or implied. See the License for the
15 | * specific language governing permissions and limitations
16 | * under the License.
17 | */
18 |
19 | package org.wso2.carbon.uiserver.api;
20 |
21 | import org.testng.Assert;
22 | import org.testng.annotations.DataProvider;
23 | import org.testng.annotations.Test;
24 |
25 | import static java.util.Arrays.asList;
26 | import static java.util.Collections.emptyList;
27 | import static java.util.Collections.singletonList;
28 |
29 | /**
30 | * Test cases for {@link Theme} class.
31 | *
32 | * @since 0.12.0
33 | */
34 | public class ThemeTest {
35 |
36 | @DataProvider
37 | public Object[][] overridableThemes() {
38 | return new Object[][]{
39 | {new Theme("t1", "p1"), new Theme("t1", "p2")},
40 | {new Theme("t1", emptyList()), new Theme("t1", singletonList("p2"))},
41 | {new Theme("t1", asList("p1", "p11")), new Theme("t1", asList("p2", "p22"))}
42 | };
43 | }
44 |
45 | @Test(dataProvider = "overridableThemes")
46 | public void testCanOverrideBy(Theme theme1, Theme theme2) {
47 | Assert.assertTrue(theme1.canOverrideBy(theme2));
48 | }
49 |
50 | @DataProvider
51 | public Object[][] equalThemes() {
52 | Theme theme = new Theme("t0", "p0");
53 | return new Object[][]{
54 | {theme, theme},
55 | {new Theme("t1", "p1"), new Theme("t1", "p1")},
56 | {new Theme("t1", emptyList()), new Theme("t1", emptyList())},
57 | {new Theme("t1", singletonList("p1")), new Theme("t1", singletonList("p1"))},
58 | {new Theme("t1", asList("p1", "p11")), new Theme("t1", asList("p1", "p11"))}
59 | };
60 | }
61 |
62 | @Test(dataProvider = "equalThemes")
63 | public void testEquals(Theme theme1, Theme theme2) {
64 | Assert.assertEquals(theme1, theme2);
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/components/org.wso2.carbon.uiserver/src/main/java/org/wso2/carbon/uiserver/internal/exception/AppCreationException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
3 | *
4 | * WSO2 Inc. licenses this file to you under the Apache License,
5 | * Version 2.0 (the "License"); you may not use this file except
6 | * in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing,
12 | * software distributed under the License is distributed on an
13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 | * KIND, either express or implied. See the License for the
15 | * specific language governing permissions and limitations
16 | * under the License.
17 | */
18 |
19 | package org.wso2.carbon.uiserver.internal.exception;
20 |
21 | import org.wso2.carbon.uiserver.api.exception.UiServerRuntimeException;
22 |
23 | /**
24 | * Indicates an error occurred when creating a web app.
25 | *
26 | * @since 0.8.0
27 | */
28 | public class AppCreationException extends UiServerRuntimeException {
29 |
30 | /**
31 | * Constructs a new exception with {@code null} as its detail message. The cause is not initialized, and may
32 | * subsequently be initialized by a call to {@link #initCause(Throwable)}.
33 | */
34 | public AppCreationException() {
35 | }
36 |
37 | /**
38 | * Constructs a new exception with the specified detail message. The cause is not initialized, and may subsequently
39 | * be initialized by a call to {@link #initCause}.
40 | *
41 | * @param message the detail message of the exception
42 | */
43 | public AppCreationException(String message) {
44 | super(message);
45 | }
46 |
47 | /**
48 | * Constructs a new exception with the specified cause and a detail message of {@code (cause==null ? null :
49 | * cause.toString())} which typically contains the class and detail message of the {@code cause}.
50 | *
51 | * @param cause the cause of the exception
52 | */
53 | public AppCreationException(Throwable cause) {
54 | super(cause);
55 | }
56 |
57 | /**
58 | * Constructs a new exception with the specified detail message and cause.
59 | *
60 | * @param message the detail message of the exception
61 | * @param cause the cause of the exception
62 | */
63 | public AppCreationException(String message, Throwable cause) {
64 | super(message, cause);
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/components/org.wso2.carbon.uiserver/src/main/java/org/wso2/carbon/uiserver/internal/exception/FileOperationException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
3 | *
4 | * WSO2 Inc. licenses this file to you under the Apache License,
5 | * Version 2.0 (the "License"); you may not use this file except
6 | * in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing,
12 | * software distributed under the License is distributed on an
13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 | * KIND, either express or implied. See the License for the
15 | * specific language governing permissions and limitations
16 | * under the License.
17 | */
18 |
19 | package org.wso2.carbon.uiserver.internal.exception;
20 |
21 |
22 | import org.wso2.carbon.uiserver.api.exception.UiServerRuntimeException;
23 |
24 | /**
25 | * Indicates an error occurred in a file system related operation.
26 | *
27 | * @since 0.8.0
28 | */
29 | public class FileOperationException extends UiServerRuntimeException {
30 |
31 | /**
32 | * Constructs a new exception with {@code null} as its detail message. The cause is not initialized, and may
33 | * subsequently be initialized by a call to {@link #initCause(Throwable)}.
34 | */
35 | public FileOperationException() {
36 | }
37 |
38 | /**
39 | * Constructs a new exception with the specified detail message. The cause is not initialized, and may
40 | * subsequently be initialized by a call to {@link #initCause}.
41 | *
42 | * @param message the detail message of the exception
43 | */
44 | public FileOperationException(String message) {
45 | super(message);
46 | }
47 |
48 | /**
49 | * Constructs a new exception with the specified cause and a detail message of {@code (cause==null ? null :
50 | * cause.toString())} which typically contains the class and detail message of the {@code cause}.
51 | *
52 | * @param cause the cause of the exception
53 | */
54 | public FileOperationException(Throwable cause) {
55 | super(cause);
56 | }
57 |
58 | /**
59 | * Constructs a new exception with the specified detail message and cause.
60 | *
61 | * @param message the detail message of the exception
62 | * @param cause the cause of the exception
63 | */
64 | public FileOperationException(String message, Throwable cause) {
65 | super(message, cause);
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/pull_request_template.md:
--------------------------------------------------------------------------------
1 | ## Purpose
2 | > Describe the problems, issues, or needs driving this feature/fix and include links to related issues in the following format: Resolves issue1, issue2, etc.
3 |
4 | ## Goals
5 | > Describe the solutions that this feature/fix will introduce to resolve the problems described above
6 |
7 | ## Approach
8 | > Describe how you are implementing the solutions. Include an animated GIF or screenshot if the change affects the UI (email documentation@wso2.com to review all UI text). Include a link to a Markdown file or Google doc if the feature write-up is too long to paste here.
9 |
10 | ## User stories
11 | > Summary of user stories addressed by this change>
12 |
13 | ## Release note
14 | > Brief description of the new feature or bug fix as it will appear in the release notes
15 |
16 | ## Documentation
17 | > Link(s) to product documentation that addresses the changes of this PR. If no doc impact, enter “N/A” plus brief explanation of why there’s no doc impact
18 |
19 | ## Training
20 | > Link to the PR for changes to the training content in https://github.com/wso2/WSO2-Training, if applicable
21 |
22 | ## Certification
23 | > Type “Sent” when you have provided new/updated certification questions, plus four answers for each question (correct answer highlighted in bold), based on this change. Certification questions/answers should be sent to certification@wso2.com and NOT pasted in this PR. If there is no impact on certification exams, type “N/A” and explain why.
24 |
25 | ## Marketing
26 | > Link to drafts of marketing content that will describe and promote this feature, including product page changes, technical articles, blog posts, videos, etc., if applicable
27 |
28 | ## Automation tests
29 | - Unit tests
30 | > Code coverage information
31 | - Integration tests
32 | > Details about the test cases and coverage
33 |
34 | ## Security checks
35 | - Followed secure coding standards in http://wso2.com/technical-reports/wso2-secure-engineering-guidelines? yes/no
36 | - Ran FindSecurityBugs plugin and verified report? yes/no
37 | - Confirmed that this PR doesn't commit any keys, passwords, tokens, usernames, or other secrets? yes/no
38 |
39 | ## Samples
40 | > Provide high-level details about the samples related to this feature
41 |
42 | ## Related PRs
43 | > List any other related PRs
44 |
45 | ## Migrations (if applicable)
46 | > Describe migration steps and platforms on which migration has been tested
47 |
48 | ## Test environment
49 | > List all JDK versions, operating systems, databases, and browser/versions on which this feature/fix was tested
50 |
51 | ## Learning
52 | > Describe the research phase and any blog posts, patterns, libraries, or add-ons you used to solve the problem.
--------------------------------------------------------------------------------
/components/org.wso2.carbon.uiserver/src/main/java/org/wso2/carbon/uiserver/internal/exception/AppDeploymentEventListenerException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
3 | *
4 | * WSO2 Inc. licenses this file to you under the Apache License,
5 | * Version 2.0 (the "License"); you may not use this file except
6 | * in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing,
12 | * software distributed under the License is distributed on an
13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 | * KIND, either express or implied. See the License for the
15 | * specific language governing permissions and limitations
16 | * under the License.
17 | */
18 |
19 | package org.wso2.carbon.uiserver.internal.exception;
20 |
21 | import org.wso2.carbon.uiserver.api.exception.UiServerRuntimeException;
22 |
23 | /**
24 | * Indicates an error occurred when invoking an app deployment event listener.
25 | *
26 | * @see org.wso2.carbon.uiserver.internal.deployment.AppDeploymentEventListener
27 | * @since 0.18.0
28 | */
29 | public class AppDeploymentEventListenerException extends UiServerRuntimeException {
30 |
31 | /**
32 | * Constructs a new exception with {@code null} as its detail message. The cause is not initialized, and may
33 | * subsequently be initialized by a call to {@link #initCause(Throwable)}.
34 | */
35 | public AppDeploymentEventListenerException() {
36 | }
37 |
38 | /**
39 | * Constructs a new exception with the specified detail message. The cause is not initialized, and may subsequently
40 | * be initialized by a call to {@link #initCause}.
41 | *
42 | * @param message the detail message of the exception
43 | */
44 | public AppDeploymentEventListenerException(String message) {
45 | super(message);
46 | }
47 |
48 | /**
49 | * Constructs a new exception with the specified cause and a detail message of {@code (cause==null ? null :
50 | * cause.toString())} which typically contains the class and detail message of the {@code cause}.
51 | *
52 | * @param cause the cause of the exception
53 | */
54 | public AppDeploymentEventListenerException(Throwable cause) {
55 | super(cause);
56 | }
57 |
58 | /**
59 | * Constructs a new exception with the specified detail message and cause.
60 | *
61 | * @param message the detail message of the exception
62 | * @param cause the cause of the exception
63 | */
64 | public AppDeploymentEventListenerException(String message, Throwable cause) {
65 | super(message, cause);
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/components/org.wso2.carbon.uiserver/src/test/java/org/wso2/carbon/uiserver/api/ExtensionTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
3 | *
4 | * WSO2 Inc. licenses this file to you under the Apache License,
5 | * Version 2.0 (the "License"); you may not use this file except
6 | * in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing,
12 | * software distributed under the License is distributed on an
13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 | * KIND, either express or implied. See the License for the
15 | * specific language governing permissions and limitations
16 | * under the License.
17 | */
18 |
19 | package org.wso2.carbon.uiserver.api;
20 |
21 | import org.testng.Assert;
22 | import org.testng.annotations.DataProvider;
23 | import org.testng.annotations.Test;
24 |
25 | import static java.util.Arrays.asList;
26 | import static java.util.Collections.emptyList;
27 | import static java.util.Collections.singletonList;
28 |
29 | /**
30 | * Test cases for {@link Extension} class.
31 | *
32 | * @since 0.12.0
33 | */
34 | public class ExtensionTest {
35 |
36 | @DataProvider
37 | public Object[][] overridableExtensions() {
38 | return new Object[][]{
39 | {new Extension("e1", "t1", "p1"), new Extension("e1", "t1", "p2")},
40 | {new Extension("e1", "t1", emptyList()), new Extension("e1", "t1", singletonList("p2"))},
41 | {new Extension("e1", "t1", asList("p1", "p11")), new Extension("e1", "t1", asList("p2", "p22"))}
42 | };
43 | }
44 |
45 | @Test(dataProvider = "overridableExtensions")
46 | public void testCanOverrideBy(Extension extension1, Extension extension2) {
47 | Assert.assertTrue(extension1.canOverrideBy(extension2));
48 | }
49 |
50 | @DataProvider
51 | public Object[][] equalExtensions() {
52 | Extension extension = new Extension("e0", "t0", "p0");
53 | return new Object[][]{
54 | {extension, extension},
55 | {new Extension("e1", "t1", "p1"), new Extension("e1", "t1", "p1")},
56 | {new Extension("e1", "t1", emptyList()), new Extension("e1", "t1", emptyList())},
57 | {new Extension("e1", "t1", singletonList("p1")), new Extension("e1", "t1", singletonList("p1"))},
58 | {new Extension("e1", "t1", asList("p1", "p11")), new Extension("e1", "t1", asList("p1", "p11"))}
59 | };
60 | }
61 |
62 | @Test(dataProvider = "equalExtensions")
63 | public void testEquals(Extension extension1, Extension extension2) {
64 | Assert.assertEquals(extension1, extension2);
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/components/org.wso2.carbon.uiserver/src/test/java/org/wso2/carbon/uiserver/api/util/MultilocationalTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
3 | *
4 | * WSO2 Inc. licenses this file to you under the Apache License,
5 | * Version 2.0 (the "License"); you may not use this file except
6 | * in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing,
12 | * software distributed under the License is distributed on an
13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 | * KIND, either express or implied. See the License for the
15 | * specific language governing permissions and limitations
16 | * under the License.
17 | */
18 |
19 | package org.wso2.carbon.uiserver.api.util;
20 |
21 | import com.google.common.collect.ImmutableList;
22 | import org.testng.Assert;
23 | import org.testng.annotations.Test;
24 |
25 | import java.util.List;
26 |
27 | /**
28 | * Test cases for {@link Multilocational} interface.
29 | *
30 | * @since 0.12.0
31 | */
32 | public class MultilocationalTest {
33 |
34 | @Test
35 | public void testGetPaths() {
36 | ImmutableList paths = ImmutableList.of("p1", "p2");
37 | Multilocational multilocational = createMultilocational(paths);
38 |
39 | Assert.assertEquals(multilocational.getPaths(), paths);
40 | }
41 |
42 | @Test
43 | public void testGetHighestPriorityPath() {
44 | ImmutableList paths = ImmutableList.of("p1", "p2");
45 | Multilocational multilocational = createMultilocational(paths);
46 |
47 | Assert.assertEquals(multilocational.getHighestPriorityPath(), "p1");
48 | }
49 |
50 | @Test
51 | public void testGetLeastPriorityPath() {
52 | ImmutableList paths = ImmutableList.of("p1", "p2");
53 | Multilocational multilocational = createMultilocational(paths);
54 |
55 | Assert.assertEquals(multilocational.getLeastPriorityPath(), "p2");
56 | }
57 |
58 | private static Multilocational createMultilocational(List paths) {
59 | return new MultilocationalImpl(paths);
60 | }
61 |
62 | /**
63 | * Implementation of {@link Multilocational} for unit tests.
64 | *
65 | * @since 0.12.0
66 | */
67 | private static class MultilocationalImpl implements Multilocational {
68 |
69 | private final List paths;
70 |
71 | /**
72 | * Creates a new instance.
73 | *
74 | * @param paths paths
75 | */
76 | public MultilocationalImpl(List paths) {
77 | this.paths = paths;
78 | }
79 |
80 | @Override
81 | public List getPaths() {
82 | return paths;
83 | }
84 | }
85 | }
86 |
--------------------------------------------------------------------------------
/components/org.wso2.carbon.uiserver/src/test/java/org/wso2/carbon/uiserver/internal/deployment/parser/YamlFileParserTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
3 | *
4 | * WSO2 Inc. licenses this file to you under the Apache License,
5 | * Version 2.0 (the "License"); you may not use this file except
6 | * in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing,
12 | * software distributed under the License is distributed on an
13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 | * KIND, either express or implied. See the License for the
15 | * specific language governing permissions and limitations
16 | * under the License.
17 | */
18 |
19 | package org.wso2.carbon.uiserver.internal.deployment.parser;
20 |
21 | import org.testng.Assert;
22 | import org.testng.annotations.Test;
23 | import org.wso2.carbon.uiserver.internal.exception.ConfigurationException;
24 | import org.wso2.carbon.uiserver.internal.exception.FileOperationException;
25 | import org.wso2.carbon.uiserver.internal.reference.FileReference;
26 |
27 | import java.util.Map;
28 |
29 | import static org.mockito.Mockito.mock;
30 | import static org.mockito.Mockito.when;
31 |
32 | /**
33 | * Test cases for {@link YamlFileParser} class.
34 | *
35 | * @since 0.12.5
36 | */
37 | public class YamlFileParserTest {
38 |
39 | @Test
40 | public void testParseWhenCannotReadFile() {
41 | FileReference fileReference = mock(FileReference.class);
42 | when(fileReference.getContent()).thenThrow(FileOperationException.class);
43 |
44 | Assert.assertThrows(ConfigurationException.class, () -> YamlFileParser.parse(fileReference, Map.class));
45 | }
46 |
47 | @Test
48 | public void testParseInvalidYaml() {
49 | FileReference fileReference = mock(FileReference.class);
50 | when(fileReference.getContent()).thenReturn("foo: bar\n -: foobar");
51 |
52 | Assert.assertThrows(ConfigurationException.class, () -> YamlFileParser.parse(fileReference, Map.class));
53 | }
54 |
55 | @Test
56 | public void testParseEmptyYaml() {
57 | FileReference fileReference = mock(FileReference.class);
58 | when(fileReference.getContent()).thenReturn("# nothing here");
59 |
60 | Assert.assertThrows(ConfigurationException.class, () -> YamlFileParser.parse(fileReference, Map.class));
61 | }
62 |
63 | @Test
64 | public void testParse() {
65 | FileReference fileReference = mock(FileReference.class);
66 | when(fileReference.getContent()).thenReturn("foo: bar\nfoobar: barz");
67 |
68 | Map map = YamlFileParser.parse(fileReference, Map.class);
69 | Assert.assertEquals(map.get("foo"), "bar");
70 | Assert.assertEquals(map.get("foobar"), "barz");
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/components/org.wso2.carbon.uiserver/src/main/java/org/wso2/carbon/uiserver/api/Page.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
3 | *
4 | * WSO2 Inc. licenses this file to you under the Apache License,
5 | * Version 2.0 (the "License"); you may not use this file except
6 | * in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing,
12 | * software distributed under the License is distributed on an
13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 | * KIND, either express or implied. See the License for the
15 | * specific language governing permissions and limitations
16 | * under the License.
17 | */
18 |
19 | package org.wso2.carbon.uiserver.api;
20 |
21 | import org.wso2.carbon.uiserver.api.exception.RenderingException;
22 | import org.wso2.carbon.uiserver.api.http.HttpRequest;
23 |
24 | import java.util.Objects;
25 |
26 | /**
27 | * Represents a page of a web app.
28 | *
29 | * @since 0.8.0
30 | */
31 | public abstract class Page implements Comparable {
32 |
33 | private final UriPatten uriPatten;
34 |
35 | /**
36 | * Creates a new page.
37 | *
38 | * @param uriPatten URI pattern of the page
39 | */
40 | public Page(UriPatten uriPatten) {
41 | this.uriPatten = uriPatten;
42 | }
43 |
44 | /**
45 | * Returns the URI pattern of this page.
46 | *
47 | * @return URI pattern of this page
48 | */
49 | public UriPatten getUriPatten() {
50 | return uriPatten;
51 | }
52 |
53 | /**
54 | * Checks whether this page matches to the given URI.
55 | *
56 | * @param uri URI to be matched
57 | * @return {@code true} iff matches, otherwise {@code false}
58 | */
59 | public boolean matches(String uri) {
60 | return uriPatten.matches(uri);
61 | }
62 |
63 | /**
64 | * Renders this page and returns a HTML document.
65 | *
66 | * @param request HTTP request
67 | * @param configuration configurations of the app
68 | * @return output html of page rendering
69 | * @throws RenderingException if an error occurred during page rendering
70 | */
71 | public abstract String render(HttpRequest request, Configuration configuration) throws RenderingException;
72 |
73 | @Override
74 | public int compareTo(Page otherPage) {
75 | return (otherPage == null) ? 1 : this.uriPatten.compareTo(otherPage.uriPatten);
76 | }
77 |
78 | @Override
79 | public boolean equals(Object obj) {
80 | return (this == obj) || ((obj instanceof Page) && (this.compareTo((Page) obj) == 0));
81 | }
82 |
83 | @Override
84 | public int hashCode() {
85 | return Objects.hash(uriPatten);
86 | }
87 |
88 | @Override
89 | public String toString() {
90 | return "Page{uriPatten=" + uriPatten + "}";
91 | }
92 | }
93 |
--------------------------------------------------------------------------------
/components/org.wso2.carbon.uiserver/src/main/java/org/wso2/carbon/uiserver/internal/io/util/MimeMapper.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
3 | *
4 | * WSO2 Inc. licenses this file to you under the Apache License,
5 | * Version 2.0 (the "License"); you may not use this file except
6 | * in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing,
12 | * software distributed under the License is distributed on an
13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 | * KIND, either express or implied. See the License for the
15 | * specific language governing permissions and limitations
16 | * under the License.
17 | */
18 |
19 | package org.wso2.carbon.uiserver.internal.io.util;
20 |
21 | import org.wso2.carbon.uiserver.api.exception.UiServerRuntimeException;
22 | import org.yaml.snakeyaml.Yaml;
23 |
24 | import java.io.IOException;
25 | import java.io.InputStream;
26 | import java.util.Map;
27 | import java.util.Optional;
28 |
29 | /**
30 | * Maps MIME types to file extensions.
31 | *
32 | * @since 0.8.0
33 | */
34 | public class MimeMapper {
35 |
36 | private static final String FILE_NAME_MIME_TYPES = "mime-types.yaml";
37 | private static Map mimeTypes;
38 |
39 | private MimeMapper() {
40 | }
41 |
42 | @SuppressWarnings("unchecked")
43 | private static Map loadMimeTypes() throws UiServerRuntimeException {
44 | try (InputStream inputStream = MimeMapper.class.getClassLoader().getResourceAsStream(FILE_NAME_MIME_TYPES)) {
45 | if (inputStream == null) {
46 | throw new UiServerRuntimeException(
47 | "Cannot find MIME types file '" + FILE_NAME_MIME_TYPES + "' in class path.");
48 | }
49 | return new Yaml().loadAs(inputStream, Map.class);
50 | } catch (IOException e) {
51 | throw new UiServerRuntimeException("Cannot read MIME types file '" + FILE_NAME_MIME_TYPES + "'.", e);
52 | } catch (Exception e) {
53 | throw new UiServerRuntimeException("MIME types file is '" + FILE_NAME_MIME_TYPES + "' is invalid.", e);
54 | }
55 | }
56 |
57 | /**
58 | * Returns the MIME type for the given file extension.
59 | *
60 | * @param extension file extension
61 | * @return MIME type for the given file extension
62 | * @throws UiServerRuntimeException if cannot find or read the MIME types file, or it is invalid
63 | */
64 | public static Optional getMimeType(String extension) throws UiServerRuntimeException {
65 | if (mimeTypes == null) {
66 | synchronized (MimeMapper.class) {
67 | if (mimeTypes == null) {
68 | mimeTypes = loadMimeTypes();
69 | }
70 | }
71 | }
72 | return Optional.ofNullable(mimeTypes.get(extension));
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/components/org.wso2.carbon.uiserver/src/main/java/org/wso2/carbon/uiserver/internal/http/PageRequestDispatcher.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
3 | *
4 | * WSO2 Inc. licenses this file to you under the Apache License,
5 | * Version 2.0 (the "License"); you may not use this file except
6 | * in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing,
12 | * software distributed under the License is distributed on an
13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 | * KIND, either express or implied. See the License for the
15 | * specific language governing permissions and limitations
16 | * under the License.
17 | */
18 |
19 | package org.wso2.carbon.uiserver.internal.http;
20 |
21 | import org.wso2.carbon.uiserver.api.App;
22 | import org.wso2.carbon.uiserver.api.exception.PageNotFoundException;
23 | import org.wso2.carbon.uiserver.api.exception.PageRedirectException;
24 | import org.wso2.carbon.uiserver.api.exception.RenderingException;
25 | import org.wso2.carbon.uiserver.api.http.HttpRequest;
26 | import org.wso2.carbon.uiserver.api.http.HttpResponse;
27 |
28 | import static org.wso2.carbon.uiserver.api.http.HttpResponse.CONTENT_TYPE_TEXT_HTML;
29 | import static org.wso2.carbon.uiserver.api.http.HttpResponse.HEADER_LOCATION;
30 |
31 | /**
32 | * Dispatcher for HTTP request for pages.
33 | *
34 | * @since 0.13.4
35 | */
36 | public class PageRequestDispatcher {
37 |
38 | private final App app;
39 |
40 | /**
41 | * Creates a new request dispatcher.
42 | *
43 | * @param app web app to be served
44 | */
45 | public PageRequestDispatcher(App app) {
46 | this.app = app;
47 | }
48 |
49 | /**
50 | * Serves to the supplied HTTP request and returns a HTTP response.
51 | *
52 | * @param request HTTP request to be served
53 | * @return a HTTP response that carries the result
54 | */
55 | public HttpResponse serve(HttpRequest request) {
56 | try {
57 | String html = app.renderPage(request);
58 | return ResponseBuilder.ok(html, CONTENT_TYPE_TEXT_HTML)
59 | .headers(app.getConfiguration().getResponseHeaders().forPages())
60 | .build();
61 | } catch (RenderingException e) {
62 | return ResponseBuilder
63 | .serverError("An error occurred when rendering page '" + request.getUriWithoutContextPath() + "'.")
64 | .build();
65 | } catch (PageNotFoundException e) {
66 | return ResponseBuilder.notFound("Page '" + request.getUriWithoutContextPath() + "' does not exists.")
67 | .build();
68 | } catch (PageRedirectException e) {
69 | return ResponseBuilder.status(e.getHttpStatusCode())
70 | .header(HEADER_LOCATION, e.getRedirectUrl())
71 | .build();
72 | }
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/components/org.wso2.carbon.uiserver/src/main/java/org/wso2/carbon/uiserver/internal/io/reference/ArtifactI18nResourceReference.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
3 | *
4 | * WSO2 Inc. licenses this file to you under the Apache License,
5 | * Version 2.0 (the "License"); you may not use this file except
6 | * in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing,
12 | * software distributed under the License is distributed on an
13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 | * KIND, either express or implied. See the License for the
15 | * specific language governing permissions and limitations
16 | * under the License.
17 | */
18 |
19 | package org.wso2.carbon.uiserver.internal.io.reference;
20 |
21 | import com.google.gson.Gson;
22 | import com.google.gson.JsonParseException;
23 | import com.google.gson.reflect.TypeToken;
24 | import org.wso2.carbon.uiserver.internal.exception.FileOperationException;
25 | import org.wso2.carbon.uiserver.internal.io.util.PathUtils;
26 | import org.wso2.carbon.uiserver.internal.reference.I18nResourceReference;
27 |
28 | import java.io.BufferedReader;
29 | import java.io.IOException;
30 | import java.lang.reflect.Type;
31 | import java.nio.charset.StandardCharsets;
32 | import java.nio.file.Files;
33 | import java.nio.file.Path;
34 | import java.util.Locale;
35 | import java.util.Map;
36 |
37 | /**
38 | * A reference to an i18n resource inside a web app artifact.
39 | *
40 | * @since 0.8.0
41 | */
42 | public class ArtifactI18nResourceReference implements I18nResourceReference {
43 |
44 | public static final String I18N_RESOURCE_FILE_EXTENSION = "json";
45 | private static final Gson GSON = new Gson();
46 | private static final Type GSON_TYPE = new TypeToken