From d548f719d80ebadb3150e43d233bf9cccd4ba0b9 Mon Sep 17 00:00:00 2001 From: Nils Christian Ehmke <nie@informatik.uni-kiel.de> Date: Mon, 3 Dec 2012 20:20:16 +0100 Subject: [PATCH] Javadoc comments; Refactoring; Added some tests --- Kieker.WebGUI/.classpath | 7 +- .../common/ClassAndMethodContainer.java | 19 ++++ .../ComponentListContainer.java | 2 +- .../IComponentContainer.java | 2 +- .../{common => domain}/PluginContainer.java | 2 +- .../RepositoryContainer.java | 2 +- .../kieker/webgui/domain/package-info.java | 2 + .../webgui/persistence/IProjectDAO.java | 2 +- .../persistence/impl/DerbyUserDAOImpl.java | 5 - .../persistence/impl/FSProjectDAOImpl.java | 6 +- .../webgui/persistence/impl/package-info.java | 22 +++++ .../persistence/impl/util/package-info.java | 22 +++++ .../webgui/persistence/package-info.java | 22 +++++ .../webgui/service/IGraphLayoutService.java | 48 ++++++++++ .../webgui/service/IProjectService.java | 24 ++++- .../impl/GraphLayoutServiceImpl.java} | 40 ++++---- .../service/impl/ProjectServiceImpl.java | 2 +- .../webgui/service/impl/UserServiceImpl.java | 5 - .../webgui/service/impl/package-info.java | 2 + .../webgui/service/impl/util/Analysis.java | 5 +- .../service/impl/util/package-info.java | 2 + .../kieker/webgui/service/package-info.java | 2 + .../web/beans/application/ProjectsBean.java | 4 +- .../beans/view/CurrentAnalysisEditorBean.java | 10 +- .../view/CurrentAnalysisEditorGraphBean.java | 8 +- .../web/beans/view/CurrentCockpitBean.java | 13 ++- .../beans/view/CurrentCockpitEditorBean.java | 6 +- .../webgui/web/converter/package-info.java | 3 +- .../common/ClassAndMethodContainerTest.java | 66 +++++++++++++ .../common/EnvironmentLoaderListenerTest.java | 47 +++++++++ .../impl/util/PluginFinderTest.java | 70 ++++++++++++++ .../converter/RoleStringConverterTest.java | 95 +++++++++++++++++++ 32 files changed, 498 insertions(+), 69 deletions(-) rename Kieker.WebGUI/src/main/java/kieker/webgui/{common => domain}/ComponentListContainer.java (98%) rename Kieker.WebGUI/src/main/java/kieker/webgui/{common => domain}/IComponentContainer.java (97%) rename Kieker.WebGUI/src/main/java/kieker/webgui/{common => domain}/PluginContainer.java (99%) rename Kieker.WebGUI/src/main/java/kieker/webgui/{common => domain}/RepositoryContainer.java (99%) create mode 100644 Kieker.WebGUI/src/main/java/kieker/webgui/persistence/impl/package-info.java create mode 100644 Kieker.WebGUI/src/main/java/kieker/webgui/persistence/impl/util/package-info.java create mode 100644 Kieker.WebGUI/src/main/java/kieker/webgui/persistence/package-info.java create mode 100644 Kieker.WebGUI/src/main/java/kieker/webgui/service/IGraphLayoutService.java rename Kieker.WebGUI/src/main/java/kieker/webgui/{common/layout/GraphFlowLayouter.java => service/impl/GraphLayoutServiceImpl.java} (90%) create mode 100644 Kieker.WebGUI/src/test/java/kieker/webgui/common/ClassAndMethodContainerTest.java create mode 100644 Kieker.WebGUI/src/test/java/kieker/webgui/common/EnvironmentLoaderListenerTest.java create mode 100644 Kieker.WebGUI/src/test/java/kieker/webgui/persistence/impl/util/PluginFinderTest.java create mode 100644 Kieker.WebGUI/src/test/java/kieker/webgui/web/converter/RoleStringConverterTest.java diff --git a/Kieker.WebGUI/.classpath b/Kieker.WebGUI/.classpath index 658fc2e3..98730f54 100644 --- a/Kieker.WebGUI/.classpath +++ b/Kieker.WebGUI/.classpath @@ -11,12 +11,7 @@ <attribute name="maven.pomderived" value="true"/> </attributes> </classpathentry> - <classpathentry kind="src" output="target/test-classes" path="src/test/java"> - <attributes> - <attribute name="optional" value="true"/> - <attribute name="maven.pomderived" value="true"/> - </attributes> - </classpathentry> + <classpathentry kind="src" path="src/test/java"/> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"> <attributes> <attribute name="maven.pomderived" value="true"/> diff --git a/Kieker.WebGUI/src/main/java/kieker/webgui/common/ClassAndMethodContainer.java b/Kieker.WebGUI/src/main/java/kieker/webgui/common/ClassAndMethodContainer.java index e1324891..c443809a 100644 --- a/Kieker.WebGUI/src/main/java/kieker/webgui/common/ClassAndMethodContainer.java +++ b/Kieker.WebGUI/src/main/java/kieker/webgui/common/ClassAndMethodContainer.java @@ -220,10 +220,25 @@ public final class ClassAndMethodContainer { * This is the loadFromFile(File)-method of the class equivalence of {@link AnalysisController}. */ private final Method analysisControllerLoadFromFile; + /** + * This is the description()-method of the class equivalence of {@link Display}. + */ private final Method displayDescriptionMethod; + /** + * This is the dependencies()-method of the class equivalence of {@link Plugin}. + */ private final Method pluginDependenciesMethod; + /** + * This is the dependencies()-method of the class equivalence of {@link Repository}. + */ private final Method repositoryDependenciesMethod; + /** + * This is the programmaticOnly()-method of the class equivalence of {@link Plugin}. + */ private final Method pluginProgrammaticOnlyMethod; + /** + * This is the programmaticOnly()-method of the class equivalence of {@link Repository}. + */ private final Method repositoryProgrammaticOnlyMethod; private final Method logImplWebguiLoggingClassGetEntriesMethod; @@ -313,15 +328,19 @@ public final class ClassAndMethodContainer { // Now the constructors this.analysisControllerThreadConstructor = this.analysisControllerThreadClass.getConstructor(this.analysisControllerClass); } catch (final ClassNotFoundException ex) { + // Something went wrong. We can do nothing except throwing an exception ClassAndMethodContainer.LOG.error(ClassAndMethodContainer.MSG_LOAD_EXCEPTION, ex); throw new ProjectLoadException(ClassAndMethodContainer.MSG_LOAD_EXCEPTION, ex); } catch (final NoSuchMethodException ex) { + // Something went wrong. We can do nothing except throwing an exception ClassAndMethodContainer.LOG.error(ClassAndMethodContainer.MSG_LOAD_EXCEPTION, ex); throw new ProjectLoadException(ClassAndMethodContainer.MSG_LOAD_EXCEPTION, ex); } catch (final SecurityException ex) { + // Something went wrong. We can do nothing except throwing an exception ClassAndMethodContainer.LOG.error(ClassAndMethodContainer.MSG_LOAD_EXCEPTION, ex); throw new ProjectLoadException(ClassAndMethodContainer.MSG_LOAD_EXCEPTION, ex); } catch (final ClassCastException ex) { + // Something went wrong. We can do nothing except throwing an exception ClassAndMethodContainer.LOG.error(ClassAndMethodContainer.MSG_LOAD_EXCEPTION, ex); throw new ProjectLoadException(ClassAndMethodContainer.MSG_LOAD_EXCEPTION, ex); } diff --git a/Kieker.WebGUI/src/main/java/kieker/webgui/common/ComponentListContainer.java b/Kieker.WebGUI/src/main/java/kieker/webgui/domain/ComponentListContainer.java similarity index 98% rename from Kieker.WebGUI/src/main/java/kieker/webgui/common/ComponentListContainer.java rename to Kieker.WebGUI/src/main/java/kieker/webgui/domain/ComponentListContainer.java index a76e74b1..0e5de465 100644 --- a/Kieker.WebGUI/src/main/java/kieker/webgui/common/ComponentListContainer.java +++ b/Kieker.WebGUI/src/main/java/kieker/webgui/domain/ComponentListContainer.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. ***************************************************************************/ -package kieker.webgui.common; +package kieker.webgui.domain; import java.util.List; diff --git a/Kieker.WebGUI/src/main/java/kieker/webgui/common/IComponentContainer.java b/Kieker.WebGUI/src/main/java/kieker/webgui/domain/IComponentContainer.java similarity index 97% rename from Kieker.WebGUI/src/main/java/kieker/webgui/common/IComponentContainer.java rename to Kieker.WebGUI/src/main/java/kieker/webgui/domain/IComponentContainer.java index 9abf5a90..bc1f14dd 100644 --- a/Kieker.WebGUI/src/main/java/kieker/webgui/common/IComponentContainer.java +++ b/Kieker.WebGUI/src/main/java/kieker/webgui/domain/IComponentContainer.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. ***************************************************************************/ -package kieker.webgui.common; +package kieker.webgui.domain; /** * This is the interface for component containers of different types (plugins and repositories). It exists to have a common base for the implementing classes. diff --git a/Kieker.WebGUI/src/main/java/kieker/webgui/common/PluginContainer.java b/Kieker.WebGUI/src/main/java/kieker/webgui/domain/PluginContainer.java similarity index 99% rename from Kieker.WebGUI/src/main/java/kieker/webgui/common/PluginContainer.java rename to Kieker.WebGUI/src/main/java/kieker/webgui/domain/PluginContainer.java index 6bcfaff2..cba5d0d4 100644 --- a/Kieker.WebGUI/src/main/java/kieker/webgui/common/PluginContainer.java +++ b/Kieker.WebGUI/src/main/java/kieker/webgui/domain/PluginContainer.java @@ -14,7 +14,7 @@ * limitations under the License. ***************************************************************************/ -package kieker.webgui.common; +package kieker.webgui.domain; import java.util.Map; diff --git a/Kieker.WebGUI/src/main/java/kieker/webgui/common/RepositoryContainer.java b/Kieker.WebGUI/src/main/java/kieker/webgui/domain/RepositoryContainer.java similarity index 99% rename from Kieker.WebGUI/src/main/java/kieker/webgui/common/RepositoryContainer.java rename to Kieker.WebGUI/src/main/java/kieker/webgui/domain/RepositoryContainer.java index 251d21a9..cc1ec626 100644 --- a/Kieker.WebGUI/src/main/java/kieker/webgui/common/RepositoryContainer.java +++ b/Kieker.WebGUI/src/main/java/kieker/webgui/domain/RepositoryContainer.java @@ -14,7 +14,7 @@ * limitations under the License. ***************************************************************************/ -package kieker.webgui.common; +package kieker.webgui.domain; import java.util.Map; diff --git a/Kieker.WebGUI/src/main/java/kieker/webgui/domain/package-info.java b/Kieker.WebGUI/src/main/java/kieker/webgui/domain/package-info.java index 3931eafb..3ebe0855 100644 --- a/Kieker.WebGUI/src/main/java/kieker/webgui/domain/package-info.java +++ b/Kieker.WebGUI/src/main/java/kieker/webgui/domain/package-info.java @@ -15,6 +15,8 @@ ***************************************************************************/ /** + * This package contains domain specific classes. + * * @author Nils Christian Ehmke */ package kieker.webgui.domain; \ No newline at end of file diff --git a/Kieker.WebGUI/src/main/java/kieker/webgui/persistence/IProjectDAO.java b/Kieker.WebGUI/src/main/java/kieker/webgui/persistence/IProjectDAO.java index b0612cbc..0a24f2e1 100644 --- a/Kieker.WebGUI/src/main/java/kieker/webgui/persistence/IProjectDAO.java +++ b/Kieker.WebGUI/src/main/java/kieker/webgui/persistence/IProjectDAO.java @@ -25,10 +25,10 @@ import org.springframework.security.access.prepost.PreAuthorize; import kieker.analysis.model.analysisMetaModel.MIProject; import kieker.webgui.common.ClassAndMethodContainer; -import kieker.webgui.common.ComponentListContainer; import kieker.webgui.common.exception.NewerProjectException; import kieker.webgui.common.exception.ProjectAlreadyExistingException; import kieker.webgui.common.exception.ProjectNotExistingException; +import kieker.webgui.domain.ComponentListContainer; import org.primefaces.model.UploadedFile; diff --git a/Kieker.WebGUI/src/main/java/kieker/webgui/persistence/impl/DerbyUserDAOImpl.java b/Kieker.WebGUI/src/main/java/kieker/webgui/persistence/impl/DerbyUserDAOImpl.java index 0d61a84a..ac122082 100644 --- a/Kieker.WebGUI/src/main/java/kieker/webgui/persistence/impl/DerbyUserDAOImpl.java +++ b/Kieker.WebGUI/src/main/java/kieker/webgui/persistence/impl/DerbyUserDAOImpl.java @@ -27,7 +27,6 @@ import javax.sql.DataSource; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.jdbc.datasource.DataSourceUtils; -import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.stereotype.Service; import kieker.common.logging.Log; @@ -64,7 +63,6 @@ public class DerbyUserDAOImpl implements IUserDAO { * @see kieker.webgui.persistence.IserDAO#addUser(user) */ @Override - @PreAuthorize("hasRole('Administrator')") public void addUser(final User user) throws DataAccessException { final Connection connection = DataSourceUtils.getConnection(this.dataSource); PreparedStatement userCmd = null; @@ -108,7 +106,6 @@ public class DerbyUserDAOImpl implements IUserDAO { * @see kieker.webgui.persistence.IserDAO#deleteUser(user) */ @Override - @PreAuthorize("hasRole('Administrator')") public void deleteUser(final User user) throws DataAccessException { final Connection connection = DataSourceUtils.getConnection(this.dataSource); PreparedStatement delCmd = null; @@ -145,7 +142,6 @@ public class DerbyUserDAOImpl implements IUserDAO { * @see kieker.webgui.persistence.IserDAO#editUser(user) */ @Override - @PreAuthorize("hasRole('Administrator')") public void editUser(final User user) throws DataAccessException { final Connection connection = DataSourceUtils.getConnection(this.dataSource); PreparedStatement updateCmd = null; @@ -196,7 +192,6 @@ public class DerbyUserDAOImpl implements IUserDAO { * @see List<User> kieker.webgui.persistence.getUsers() */ @Override - @PreAuthorize("hasRole('Administrator')") public List<User> getUsers() throws DataAccessException { final Connection connection = DataSourceUtils.getConnection(this.dataSource); final List<User> result = new ArrayList<User>(); diff --git a/Kieker.WebGUI/src/main/java/kieker/webgui/persistence/impl/FSProjectDAOImpl.java b/Kieker.WebGUI/src/main/java/kieker/webgui/persistence/impl/FSProjectDAOImpl.java index d86c900c..d9ccf5c1 100644 --- a/Kieker.WebGUI/src/main/java/kieker/webgui/persistence/impl/FSProjectDAOImpl.java +++ b/Kieker.WebGUI/src/main/java/kieker/webgui/persistence/impl/FSProjectDAOImpl.java @@ -73,13 +73,13 @@ import kieker.analysis.repository.AbstractRepository; import kieker.common.logging.Log; import kieker.common.logging.LogFactory; import kieker.webgui.common.ClassAndMethodContainer; -import kieker.webgui.common.ComponentListContainer; -import kieker.webgui.common.PluginContainer; -import kieker.webgui.common.RepositoryContainer; import kieker.webgui.common.exception.ComponentInitializationException; import kieker.webgui.common.exception.NewerProjectException; import kieker.webgui.common.exception.ProjectAlreadyExistingException; import kieker.webgui.common.exception.ProjectNotExistingException; +import kieker.webgui.domain.ComponentListContainer; +import kieker.webgui.domain.PluginContainer; +import kieker.webgui.domain.RepositoryContainer; import kieker.webgui.persistence.IProjectDAO; import kieker.webgui.persistence.impl.util.CloseableURLClassLoader; import kieker.webgui.persistence.impl.util.PluginFinder; diff --git a/Kieker.WebGUI/src/main/java/kieker/webgui/persistence/impl/package-info.java b/Kieker.WebGUI/src/main/java/kieker/webgui/persistence/impl/package-info.java new file mode 100644 index 00000000..3ff2a9a4 --- /dev/null +++ b/Kieker.WebGUI/src/main/java/kieker/webgui/persistence/impl/package-info.java @@ -0,0 +1,22 @@ +/*************************************************************************** + * Copyright 2012 Kieker Project (http://kieker-monitoring.net) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ***************************************************************************/ + +/** + * This package contains the actual implementations of the persistence interfaces. + * + * @author Nils Christian Ehmke + */ +package kieker.webgui.persistence.impl; \ No newline at end of file diff --git a/Kieker.WebGUI/src/main/java/kieker/webgui/persistence/impl/util/package-info.java b/Kieker.WebGUI/src/main/java/kieker/webgui/persistence/impl/util/package-info.java new file mode 100644 index 00000000..379dd692 --- /dev/null +++ b/Kieker.WebGUI/src/main/java/kieker/webgui/persistence/impl/util/package-info.java @@ -0,0 +1,22 @@ +/*************************************************************************** + * Copyright 2012 Kieker Project (http://kieker-monitoring.net) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ***************************************************************************/ + +/** + * This package contains classes used by the persistence implementation. + * + * @author Nils Christian Ehmke + */ +package kieker.webgui.persistence.impl.util; \ No newline at end of file diff --git a/Kieker.WebGUI/src/main/java/kieker/webgui/persistence/package-info.java b/Kieker.WebGUI/src/main/java/kieker/webgui/persistence/package-info.java new file mode 100644 index 00000000..318bd0df --- /dev/null +++ b/Kieker.WebGUI/src/main/java/kieker/webgui/persistence/package-info.java @@ -0,0 +1,22 @@ +/*************************************************************************** + * Copyright 2012 Kieker Project (http://kieker-monitoring.net) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ***************************************************************************/ + +/** + * This package contains the interfaces to access the persistence. + * + * @author Nils Christian Ehmke + */ +package kieker.webgui.persistence; \ No newline at end of file diff --git a/Kieker.WebGUI/src/main/java/kieker/webgui/service/IGraphLayoutService.java b/Kieker.WebGUI/src/main/java/kieker/webgui/service/IGraphLayoutService.java new file mode 100644 index 00000000..8ab7dd2d --- /dev/null +++ b/Kieker.WebGUI/src/main/java/kieker/webgui/service/IGraphLayoutService.java @@ -0,0 +1,48 @@ +/*************************************************************************** + * Copyright 2012 Kieker Project (http://kieker-monitoring.net) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ***************************************************************************/ + +package kieker.webgui.service; + +import org.springframework.security.access.prepost.PreAuthorize; + +import kieker.webgui.common.exception.InvalidInputSizeException; +import kieker.webgui.common.exception.UninitializedGraphException; + +/** + * An interface for a service providing a graph layouter. + * + * @author Nils Christian Ehmke + */ +public interface IGraphLayoutService { + + /** + * This method takes two Strings, describing some basic graph information, and constructs a KGraph, which is then layouted by a Kieler algorithm. + * + * @param nodes + * A String containing node dimensions. + * @param edges + * A String containing connection information of edges. + * @return A String of space separated node positions. + * + * @throws UninitializedGraphException + * If the graph has not been initialized yet. + * @throws InvalidInputSizeException + * If the input size is somehow invalid. + */ + @PreAuthorize("isAuthenticated()") + public String layoutGraph(String nodes, String edges) throws UninitializedGraphException, InvalidInputSizeException; + +} diff --git a/Kieker.WebGUI/src/main/java/kieker/webgui/service/IProjectService.java b/Kieker.WebGUI/src/main/java/kieker/webgui/service/IProjectService.java index 7e4d7f9e..dc107b21 100644 --- a/Kieker.WebGUI/src/main/java/kieker/webgui/service/IProjectService.java +++ b/Kieker.WebGUI/src/main/java/kieker/webgui/service/IProjectService.java @@ -20,16 +20,18 @@ import java.io.IOException; import java.util.Collection; import java.util.List; +import org.springframework.security.access.prepost.PreAuthorize; + import kieker.analysis.AnalysisController.STATE; import kieker.analysis.model.analysisMetaModel.MIProject; import kieker.webgui.common.ClassAndMethodContainer; -import kieker.webgui.common.ComponentListContainer; import kieker.webgui.common.exception.AnalysisInitializationException; import kieker.webgui.common.exception.AnalysisStateException; import kieker.webgui.common.exception.DisplayNotFoundException; import kieker.webgui.common.exception.NewerProjectException; import kieker.webgui.common.exception.ProjectAlreadyExistingException; import kieker.webgui.common.exception.ProjectNotExistingException; +import kieker.webgui.domain.ComponentListContainer; import org.primefaces.model.UploadedFile; @@ -55,6 +57,7 @@ public interface IProjectService { * @throws IOException * If something went wrong during the creation of the project. */ + @PreAuthorize("hasAnyRole('User', 'Administrator')") public void addProject(final String projectName, final String username) throws ProjectAlreadyExistingException, IOException; /** @@ -72,6 +75,7 @@ public interface IProjectService { * @throws IOException * If something went wrong during the creation of the target-project or during the loading of the source-project. */ + @PreAuthorize("hasAnyRole('User', 'Administrator')") public void copyProject(final String originalProjectName, final String newProjectName) throws ProjectNotExistingException, ProjectAlreadyExistingException, IOException; @@ -86,6 +90,7 @@ public interface IProjectService { * @throws IOException * If something went wrong during the opening of the project. */ + @PreAuthorize("isAuthenticated()") public MIProject openProject(final String projectName) throws ProjectNotExistingException, IOException; /** @@ -103,6 +108,7 @@ public interface IProjectService { * @throws IOException * If something went wrong during the opening of the project. This can also mean that the given {@link ClassAndMethodContainer} is somehow invalid. */ + @PreAuthorize("isAuthenticated()") public Object openProject(final String projectName, final ClassAndMethodContainer classAndMethodContainer) throws ProjectNotExistingException, IOException; /** @@ -125,6 +131,7 @@ public interface IProjectService { * @throws NewerProjectException * If the project on the file system is newer and the overwriteNewerProject-flag has not been set. */ + @PreAuthorize("hasAnyRole('User', 'Administrator')") public void saveProject(final String projectName, final MIProject project, final long timeStamp, final boolean overwriteNewerProject) throws ProjectNotExistingException, IOException, NewerProjectException; @@ -137,6 +144,7 @@ public interface IProjectService { * @throws ProjectNotExistingException * If a project with the given name does not exist. */ + @PreAuthorize("isAuthenticated()") public long getCurrTimeStamp(final String projectName) throws ProjectNotExistingException; /** @@ -148,6 +156,7 @@ public interface IProjectService { * @throws ProjectNotExistingException * If a project with the given name does not exist. */ + @PreAuthorize("isAuthenticated()") public String getOwner(final String projectName) throws ProjectNotExistingException; /** @@ -162,6 +171,7 @@ public interface IProjectService { * @throws IOException * If something went wrong during the uploading. */ + @PreAuthorize("hasAnyRole('User', 'Administrator')") public void uploadLibrary(final UploadedFile file, final String projectName) throws ProjectNotExistingException, IOException; /** @@ -177,6 +187,7 @@ public interface IProjectService { * @throws IOException * If something went wrong during the initialization of the class loader. */ + @PreAuthorize("isAuthenticated()") public ClassLoader getClassLoader(final String projectName, final Object requester) throws ProjectNotExistingException, IOException; /** @@ -188,6 +199,7 @@ public interface IProjectService { * @throws ProjectNotExistingException * If a project with the given name does not exist. */ + @PreAuthorize("isAuthenticated()") public List<String> listAllLibraries(final String projectName) throws ProjectNotExistingException; /** @@ -197,6 +209,7 @@ public interface IProjectService { * The project whose components should be loaded. * @return An object containing the available components as model instances. */ + @PreAuthorize("isAuthenticated()") public abstract ComponentListContainer getAvailableComponents(String project); /** @@ -204,6 +217,7 @@ public interface IProjectService { * * @return A list containing all available project names. */ + @PreAuthorize("isAuthenticated()") public Collection<String> listAllProjects(); /** @@ -220,6 +234,7 @@ public interface IProjectService { * @throws AnalysisInitializationException * If an error occurred during the initialization of the analysis. */ + @PreAuthorize("hasAnyRole('User', 'Administrator')") public void initializeAnalysis(final String projectName, final ClassLoader classLoader) throws ProjectNotExistingException, AnalysisStateException, AnalysisInitializationException; @@ -233,6 +248,7 @@ public interface IProjectService { * @throws AnalysisStateException * If the analysis of the given project is in the wrong state to be cleaned. This means that it has not been terminated yet. */ + @PreAuthorize("hasAnyRole('User', 'Administrator')") public void cleanAnalysis(final String projectName) throws ProjectNotExistingException, AnalysisStateException; /** @@ -245,6 +261,7 @@ public interface IProjectService { * @throws AnalysisStateException * If the analysis of the given project is in the wrong state to be started. This means that it has not been initialized yet. */ + @PreAuthorize("hasAnyRole('User', 'Administrator')") public void startAnalysis(final String projectName) throws ProjectNotExistingException, AnalysisStateException; /** @@ -257,6 +274,7 @@ public interface IProjectService { * @throws AnalysisStateException * If the analysis of the given project is in the wrong state to be stopped. This means that it has not been started yet or is no longer running. */ + @PreAuthorize("hasAnyRole('User', 'Administrator')") public void stopAnalysis(final String projectName) throws ProjectNotExistingException, AnalysisStateException; /** @@ -275,6 +293,7 @@ public interface IProjectService { * @throws DisplayNotFoundException * If a view or a display within the given view does not exist. */ + @PreAuthorize("isAuthenticated()") public Object getDisplay(final String projectName, final String viewName, final String displayName) throws ProjectNotExistingException, DisplayNotFoundException; /** @@ -284,6 +303,7 @@ public interface IProjectService { * The name of the project whose state have to be returned. * @return The state of the given project, if available. {@code null} otherwise. */ + @PreAuthorize("isAuthenticated()") public STATE getCurrentState(final String projectName); /** @@ -295,6 +315,7 @@ public interface IProjectService { * @throws AnalysisStateException * If the analysis is in an invalid state to deliver the entries. */ + @PreAuthorize("isAuthenticated()") public Object[] getLogEntries(final String projectName) throws AnalysisStateException; /** @@ -308,5 +329,6 @@ public interface IProjectService { * @throws IOException * If something went wrong during the reloading of the components. */ + @PreAuthorize("hasAnyRole('User', 'Administrator')") public boolean deleteLibrary(String projectName, String libName) throws IOException; } diff --git a/Kieker.WebGUI/src/main/java/kieker/webgui/common/layout/GraphFlowLayouter.java b/Kieker.WebGUI/src/main/java/kieker/webgui/service/impl/GraphLayoutServiceImpl.java similarity index 90% rename from Kieker.WebGUI/src/main/java/kieker/webgui/common/layout/GraphFlowLayouter.java rename to Kieker.WebGUI/src/main/java/kieker/webgui/service/impl/GraphLayoutServiceImpl.java index c233fd10..86570b14 100644 --- a/Kieker.WebGUI/src/main/java/kieker/webgui/common/layout/GraphFlowLayouter.java +++ b/Kieker.WebGUI/src/main/java/kieker/webgui/service/impl/GraphLayoutServiceImpl.java @@ -14,13 +14,16 @@ * limitations under the License. ***************************************************************************/ -package kieker.webgui.common.layout; +package kieker.webgui.service.impl; import java.util.ArrayList; import java.util.List; +import org.springframework.stereotype.Service; + import kieker.webgui.common.exception.InvalidInputSizeException; import kieker.webgui.common.exception.UninitializedGraphException; +import kieker.webgui.service.IGraphLayoutService; import org.eclipse.emf.common.util.EList; @@ -47,12 +50,13 @@ import de.cau.cs.kieler.klay.layered.LayeredLayoutProvider; * * @author row, Nils Christian Ehmke */ -public final class GraphFlowLayouter { +@Service +public final class GraphLayoutServiceImpl implements IGraphLayoutService { /** - * Private constructor as this is a utility class. + * Default constructor. <b>Do not use this constructor. This bean is Spring managed.</b> */ - private GraphFlowLayouter() { + public GraphLayoutServiceImpl() { // No code necessary } @@ -226,28 +230,18 @@ public final class GraphFlowLayouter { final List<KEdge> edges = new ArrayList<KEdge>(edgeInfo.length / 4); final LayoutInformation layoutInformation = new LayoutInformation(KimlUtil.createInitializedNode(), children, edges); - GraphFlowLayouter.addNodes(positions, layoutInformation); - GraphFlowLayouter.addEdges(edgeInfo, layoutInformation); + GraphLayoutServiceImpl.addNodes(positions, layoutInformation); + GraphLayoutServiceImpl.addEdges(edgeInfo, layoutInformation); return layoutInformation; } - /** - * This method takes two Strings, describing some basic graph information, and constructs a KGraph, which is then layouted by a Kieler algorithm. - * - * @param nodes - * A String containing node dimensions. - * @param edges - * A String containing connection information of edges. - * @return A String of space separated node positions. - * - * @throws UninitializedGraphException - * If the graph has not been initialized yet. - * @throws InvalidInputSizeException - * If the input size is somehow invalid. + /* (non-Javadoc) + * @see kieker.webgui.service.impl.IGraphLayoutService#layoutGraph(java.lang.String, java.lang.String) */ - public static String layoutGraph(final String nodes, final String edges) throws UninitializedGraphException, InvalidInputSizeException { - final LayoutInformation layoutInformation = GraphFlowLayouter.assembleLayoutInformation(nodes, edges); + @Override + public String layoutGraph(final String nodes, final String edges) throws UninitializedGraphException, InvalidInputSizeException { + final LayoutInformation layoutInformation = GraphLayoutServiceImpl.assembleLayoutInformation(nodes, edges); // Create a progress monitor final IKielerProgressMonitor progressMonitor = new BasicProgressMonitor(); @@ -259,8 +253,8 @@ public final class GraphFlowLayouter { layoutProvider.doLayout(layoutInformation.getGraph(), progressMonitor); // convert layouted graph positions to String - final String layoutedGraph = GraphFlowLayouter.getPositions(layoutInformation); - final String bendPoints = GraphFlowLayouter.getBendPoints(layoutInformation); + final String layoutedGraph = GraphLayoutServiceImpl.getPositions(layoutInformation); + final String bendPoints = GraphLayoutServiceImpl.getBendPoints(layoutInformation); return layoutedGraph + "#" + bendPoints; } diff --git a/Kieker.WebGUI/src/main/java/kieker/webgui/service/impl/ProjectServiceImpl.java b/Kieker.WebGUI/src/main/java/kieker/webgui/service/impl/ProjectServiceImpl.java index 568abefd..02c9e8f3 100644 --- a/Kieker.WebGUI/src/main/java/kieker/webgui/service/impl/ProjectServiceImpl.java +++ b/Kieker.WebGUI/src/main/java/kieker/webgui/service/impl/ProjectServiceImpl.java @@ -27,13 +27,13 @@ import org.springframework.stereotype.Service; import kieker.analysis.AnalysisController.STATE; import kieker.analysis.model.analysisMetaModel.MIProject; import kieker.webgui.common.ClassAndMethodContainer; -import kieker.webgui.common.ComponentListContainer; import kieker.webgui.common.exception.AnalysisInitializationException; import kieker.webgui.common.exception.AnalysisStateException; import kieker.webgui.common.exception.DisplayNotFoundException; import kieker.webgui.common.exception.NewerProjectException; import kieker.webgui.common.exception.ProjectAlreadyExistingException; import kieker.webgui.common.exception.ProjectNotExistingException; +import kieker.webgui.domain.ComponentListContainer; import kieker.webgui.persistence.IProjectDAO; import kieker.webgui.service.IProjectService; import kieker.webgui.service.impl.util.ACManager; diff --git a/Kieker.WebGUI/src/main/java/kieker/webgui/service/impl/UserServiceImpl.java b/Kieker.WebGUI/src/main/java/kieker/webgui/service/impl/UserServiceImpl.java index 23ac5118..7fbfc072 100644 --- a/Kieker.WebGUI/src/main/java/kieker/webgui/service/impl/UserServiceImpl.java +++ b/Kieker.WebGUI/src/main/java/kieker/webgui/service/impl/UserServiceImpl.java @@ -18,7 +18,6 @@ package kieker.webgui.service.impl; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.stereotype.Service; import kieker.webgui.common.exception.DataAccessException; @@ -50,7 +49,6 @@ public class UserServiceImpl implements IUserService { * @see kieker.webgui.service.IUserService#addUser(kieker.webgui.domain.User) */ @Override - @PreAuthorize("hasRole('Administrator')") public void addUser(final User user) throws DataAccessException { this.userDAO.addUser(user); } @@ -61,7 +59,6 @@ public class UserServiceImpl implements IUserService { * @see kieker.webgui.service.IUserService#getUsers() */ @Override - @PreAuthorize("hasRole('Administrator')") public List<User> getUsers() throws DataAccessException { return this.userDAO.getUsers(); } @@ -72,7 +69,6 @@ public class UserServiceImpl implements IUserService { * @see kieker.webgui.service.IUserService#deleteUser(kieker.webgui.domain.User) */ @Override - @PreAuthorize("hasRole('Administrator')") public void deleteUser(final User user) throws DataAccessException { this.userDAO.deleteUser(user); } @@ -83,7 +79,6 @@ public class UserServiceImpl implements IUserService { * @see kieker.webgui.service.IUserService#editUser(kieker.webgui.domain.User) */ @Override - @PreAuthorize("hasRole('Administrator')") public void editUser(final User user) throws DataAccessException { this.userDAO.editUser(user); } diff --git a/Kieker.WebGUI/src/main/java/kieker/webgui/service/impl/package-info.java b/Kieker.WebGUI/src/main/java/kieker/webgui/service/impl/package-info.java index 87c267d4..11adc57a 100644 --- a/Kieker.WebGUI/src/main/java/kieker/webgui/service/impl/package-info.java +++ b/Kieker.WebGUI/src/main/java/kieker/webgui/service/impl/package-info.java @@ -15,6 +15,8 @@ ***************************************************************************/ /** + * This package contains the actual implementation of the services. + * * @author Nils Christian Ehmke */ package kieker.webgui.service.impl; \ No newline at end of file diff --git a/Kieker.WebGUI/src/main/java/kieker/webgui/service/impl/util/Analysis.java b/Kieker.WebGUI/src/main/java/kieker/webgui/service/impl/util/Analysis.java index bf72d284..d375d08c 100644 --- a/Kieker.WebGUI/src/main/java/kieker/webgui/service/impl/util/Analysis.java +++ b/Kieker.WebGUI/src/main/java/kieker/webgui/service/impl/util/Analysis.java @@ -36,12 +36,15 @@ import kieker.webgui.common.exception.ProjectLoadException; * @author Nils Christian Ehmke */ public final class Analysis { + private static final Log LOG = LogFactory.getLog(Analysis.class); + private static final long MAX_THREAD_WAIT_TIME_MS = 1000; + private final ClassAndMethodContainer classAndMethodContainer; + private final UpdateDisplaysThread updateDisplaysThread; private final Object analysisController; private final Object analysisControllerThread; - private final UpdateDisplaysThread updateDisplaysThread; /** * Creates a new instance of this class using the given parameters. diff --git a/Kieker.WebGUI/src/main/java/kieker/webgui/service/impl/util/package-info.java b/Kieker.WebGUI/src/main/java/kieker/webgui/service/impl/util/package-info.java index 9ee71288..53c03fde 100644 --- a/Kieker.WebGUI/src/main/java/kieker/webgui/service/impl/util/package-info.java +++ b/Kieker.WebGUI/src/main/java/kieker/webgui/service/impl/util/package-info.java @@ -15,6 +15,8 @@ ***************************************************************************/ /** + * This package contains classes used by the service implementation. + * * @author Nils Christian Ehmke */ package kieker.webgui.service.impl.util; \ No newline at end of file diff --git a/Kieker.WebGUI/src/main/java/kieker/webgui/service/package-info.java b/Kieker.WebGUI/src/main/java/kieker/webgui/service/package-info.java index ee1129d2..b5b19ce0 100644 --- a/Kieker.WebGUI/src/main/java/kieker/webgui/service/package-info.java +++ b/Kieker.WebGUI/src/main/java/kieker/webgui/service/package-info.java @@ -15,6 +15,8 @@ ***************************************************************************/ /** + * This package contains the interfaces to access the services. + * * @author Nils Christian Ehmke */ package kieker.webgui.service; \ No newline at end of file diff --git a/Kieker.WebGUI/src/main/java/kieker/webgui/web/beans/application/ProjectsBean.java b/Kieker.WebGUI/src/main/java/kieker/webgui/web/beans/application/ProjectsBean.java index 6afa88c1..2b2f42e7 100644 --- a/Kieker.WebGUI/src/main/java/kieker/webgui/web/beans/application/ProjectsBean.java +++ b/Kieker.WebGUI/src/main/java/kieker/webgui/web/beans/application/ProjectsBean.java @@ -44,7 +44,7 @@ import kieker.webgui.web.beans.view.CurrentProjectOverviewBean; * The {@link ProjectsBean} is a Spring managed bean to manage a list with all application wide available projects. It provides methods to receive this list as well * as methods to add, create, rename, open and copy projects. Furthermore the state of existing projects (like the timestamp or the state of the analysis) can be * received via this bean. In order to realize a good abstraction, this bean should be used for most accesses to the projects. The necessary synchronization is - * achieved in the {@link IProjectManager}.<br> + * achieved in the {@link IProjectService}.<br> * As this bean contains the whole list of the available projects, it is session scoped. There is no reason for multiple instances of this class. * * @author Nils Christian Ehmke @@ -150,7 +150,7 @@ public final class ProjectsBean { /** * This method can be used to open an already existing project. This means that the current state of the project on the file system is loaded into an instance of - * {@link MIProject}. This instance can be modified at will and for example later saved by the {@link IProjectManager}. + * {@link MIProject}. This instance can be modified at will and for example later saved by the {@link IProjectService}. * * @param project * The name of the project to be opened. diff --git a/Kieker.WebGUI/src/main/java/kieker/webgui/web/beans/view/CurrentAnalysisEditorBean.java b/Kieker.WebGUI/src/main/java/kieker/webgui/web/beans/view/CurrentAnalysisEditorBean.java index 768fbc7c..22d813a1 100644 --- a/Kieker.WebGUI/src/main/java/kieker/webgui/web/beans/view/CurrentAnalysisEditorBean.java +++ b/Kieker.WebGUI/src/main/java/kieker/webgui/web/beans/view/CurrentAnalysisEditorBean.java @@ -42,14 +42,14 @@ import kieker.analysis.model.analysisMetaModel.MIRepositoryConnector; import kieker.analysis.model.analysisMetaModel.impl.MAnalysisMetaModelFactory; import kieker.common.logging.Log; import kieker.common.logging.LogFactory; -import kieker.webgui.common.ComponentListContainer; -import kieker.webgui.common.IComponentContainer; -import kieker.webgui.common.PluginContainer; -import kieker.webgui.common.RepositoryContainer; import kieker.webgui.common.exception.LibraryLoadException; import kieker.webgui.common.exception.NewerProjectException; import kieker.webgui.common.exception.ProjectLoadException; import kieker.webgui.common.exception.ProjectNotExistingException; +import kieker.webgui.domain.ComponentListContainer; +import kieker.webgui.domain.IComponentContainer; +import kieker.webgui.domain.PluginContainer; +import kieker.webgui.domain.RepositoryContainer; import kieker.webgui.service.IProjectService; import kieker.webgui.web.beans.application.GlobalPropertiesBean; import kieker.webgui.web.beans.application.ProjectsBean; @@ -72,8 +72,6 @@ import org.eclipse.emf.ecore.EObject; */ @Component @Scope("view") -// TODO Remove libraries in a clean way -// TODO Receive libraries once as MIDependencies instead of Strings public final class CurrentAnalysisEditorBean { private static final Log LOG = LogFactory.getLog(CurrentAnalysisEditorBean.class); diff --git a/Kieker.WebGUI/src/main/java/kieker/webgui/web/beans/view/CurrentAnalysisEditorGraphBean.java b/Kieker.WebGUI/src/main/java/kieker/webgui/web/beans/view/CurrentAnalysisEditorGraphBean.java index 39a9ae0b..e4ca8e11 100644 --- a/Kieker.WebGUI/src/main/java/kieker/webgui/web/beans/view/CurrentAnalysisEditorGraphBean.java +++ b/Kieker.WebGUI/src/main/java/kieker/webgui/web/beans/view/CurrentAnalysisEditorGraphBean.java @@ -20,6 +20,7 @@ import java.util.Map; import javax.faces.context.FacesContext; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Component; @@ -36,7 +37,7 @@ import kieker.common.logging.LogFactory; import kieker.monitoring.core.registry.Registry; import kieker.webgui.common.exception.InvalidInputSizeException; import kieker.webgui.common.exception.UninitializedGraphException; -import kieker.webgui.common.layout.GraphFlowLayouter; +import kieker.webgui.service.IGraphLayoutService; import org.primefaces.context.RequestContext; @@ -160,6 +161,9 @@ public final class CurrentAnalysisEditorGraphBean { private boolean gridEnabled = false; // NOPMD (The field IS accessed later) private boolean snapEnabled = false; // NOPMD (The field IS accessed later) + @Autowired + private IGraphLayoutService layouter; + /** * This map contains all components (plugins, repositories and ports) within the graph to identify them with a unique ID. */ @@ -215,7 +219,7 @@ public final class CurrentAnalysisEditorGraphBean { final String edges = paramMap.get("edges"); // Calculate the layout - final String newLayout = GraphFlowLayouter.layoutGraph(nodes, edges); + final String newLayout = this.layouter.layoutGraph(nodes, edges); // Now use it RequestContext.getCurrentInstance().execute(String.format(CurrentAnalysisEditorGraphBean.JS_CMD_LOAD_FROM_LAYOUT, newLayout)); diff --git a/Kieker.WebGUI/src/main/java/kieker/webgui/web/beans/view/CurrentCockpitBean.java b/Kieker.WebGUI/src/main/java/kieker/webgui/web/beans/view/CurrentCockpitBean.java index d16f63c3..632cd5cc 100644 --- a/Kieker.WebGUI/src/main/java/kieker/webgui/web/beans/view/CurrentCockpitBean.java +++ b/Kieker.WebGUI/src/main/java/kieker/webgui/web/beans/view/CurrentCockpitBean.java @@ -60,16 +60,20 @@ public final class CurrentCockpitBean { private static final int NUMBER_COLUMNS = 2; private static final Log LOG = LogFactory.getLog(CurrentCockpitBean.class); - @Autowired - private IProjectService projectService; + private String projectName; private MIProject project; private MIView activeView; private ClassAndMethodContainer classAndMethodContainer; private Dashboard dashboard; private DashboardModel dashboardModel; + + @Autowired + private IProjectService projectService; @Autowired private ProjectsBean projectsBean; + @Autowired + private GlobalPropertiesBean globalPropertiesBean; /** * Creates a new instance of this class. <b>Do not call this constructor manually. It will only be accessed by Spring.</b> @@ -170,7 +174,6 @@ public final class CurrentCockpitBean { * Spring.</b> */ public synchronized void initalize() { - // TODO Replace the log messages with the localizes messages try { // Make sure that the initialization will only be done for the init request. if (!FacesContext.getCurrentInstance().isPostback()) { @@ -183,11 +186,11 @@ public final class CurrentCockpitBean { } } catch (final ProjectNotExistingException ex) { CurrentCockpitBean.LOG.error("An error occured while loading the project.", ex); - GlobalPropertiesBean.showMessage(FacesMessage.SEVERITY_ERROR, "An error occured while loading the project."); + GlobalPropertiesBean.showMessage(FacesMessage.SEVERITY_ERROR, this.globalPropertiesBean.getMsgProjectLoadingException()); } catch (final NullPointerException ex) { // This exception occurs, when the projectsBean has not been initialized CurrentCockpitBean.LOG.error("An error occured while loading the project.", ex); - GlobalPropertiesBean.showMessage(FacesMessage.SEVERITY_ERROR, "An error occured while loading the project."); + GlobalPropertiesBean.showMessage(FacesMessage.SEVERITY_ERROR, this.globalPropertiesBean.getMsgProjectLoadingException()); } } diff --git a/Kieker.WebGUI/src/main/java/kieker/webgui/web/beans/view/CurrentCockpitEditorBean.java b/Kieker.WebGUI/src/main/java/kieker/webgui/web/beans/view/CurrentCockpitEditorBean.java index ae1e9aa3..8253cddf 100644 --- a/Kieker.WebGUI/src/main/java/kieker/webgui/web/beans/view/CurrentCockpitEditorBean.java +++ b/Kieker.WebGUI/src/main/java/kieker/webgui/web/beans/view/CurrentCockpitEditorBean.java @@ -39,12 +39,12 @@ import kieker.analysis.model.analysisMetaModel.MIView; import kieker.analysis.model.analysisMetaModel.impl.MAnalysisMetaModelFactory; import kieker.common.logging.Log; import kieker.common.logging.LogFactory; -import kieker.webgui.common.ComponentListContainer; -import kieker.webgui.common.PluginContainer; -import kieker.webgui.common.RepositoryContainer; import kieker.webgui.common.exception.NewerProjectException; import kieker.webgui.common.exception.ProjectLoadException; import kieker.webgui.common.exception.ProjectNotExistingException; +import kieker.webgui.domain.ComponentListContainer; +import kieker.webgui.domain.PluginContainer; +import kieker.webgui.domain.RepositoryContainer; import kieker.webgui.service.IProjectService; import kieker.webgui.web.beans.application.GlobalPropertiesBean; import kieker.webgui.web.beans.application.ProjectsBean; diff --git a/Kieker.WebGUI/src/main/java/kieker/webgui/web/converter/package-info.java b/Kieker.WebGUI/src/main/java/kieker/webgui/web/converter/package-info.java index 1bfdcb1b..828c3505 100644 --- a/Kieker.WebGUI/src/main/java/kieker/webgui/web/converter/package-info.java +++ b/Kieker.WebGUI/src/main/java/kieker/webgui/web/converter/package-info.java @@ -15,7 +15,8 @@ ***************************************************************************/ /** + * This package contains the JSF converters. + * * @author Nils Christian Ehmke - * */ package kieker.webgui.web.converter; \ No newline at end of file diff --git a/Kieker.WebGUI/src/test/java/kieker/webgui/common/ClassAndMethodContainerTest.java b/Kieker.WebGUI/src/test/java/kieker/webgui/common/ClassAndMethodContainerTest.java new file mode 100644 index 00000000..fe8e6bc5 --- /dev/null +++ b/Kieker.WebGUI/src/test/java/kieker/webgui/common/ClassAndMethodContainerTest.java @@ -0,0 +1,66 @@ +/*************************************************************************** + * Copyright 2012 Kieker Project (http://kieker-monitoring.net) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ***************************************************************************/ + +package kieker.webgui.common; + +import java.io.IOException; +import java.net.URL; + +import org.junit.Assert; +import org.junit.Test; + +import kieker.webgui.common.exception.ProjectLoadException; +import kieker.webgui.persistence.impl.util.CloseableURLClassLoader; + +/** + * Test class for {@link ClassAndMethodContainer}. + * + * @author Nils Christian Ehmke + */ +public class ClassAndMethodContainerTest { + + private static final String KIEKER_LIB = "kieker-1.7-SNAPSHOT_emf.jar"; + + /** + * Default constructor. <b>Do not use this constructor. This is just a test class and not to be used outside a JUnit test!</b> + */ + public ClassAndMethodContainerTest() { + // No code necessary + } + + /** + * A test of this test class. + */ + @Test + public void testKiekerAvailable() { + final URL kiekerURL = Thread.currentThread().getContextClassLoader().getResource(ClassAndMethodContainerTest.KIEKER_LIB); + final CloseableURLClassLoader classLoader = new CloseableURLClassLoader(new URL[] { kiekerURL }, null); + + // If this fails, we know that kieker is not available here + try { + new ClassAndMethodContainer(classLoader); + } catch (final ProjectLoadException ex) { + Assert.fail("Kieker dependency not available."); + } + + try { + classLoader.close(); + } catch (final IOException ex) { + Assert.fail("An exception occured while closing the classloader."); + } + } + +} diff --git a/Kieker.WebGUI/src/test/java/kieker/webgui/common/EnvironmentLoaderListenerTest.java b/Kieker.WebGUI/src/test/java/kieker/webgui/common/EnvironmentLoaderListenerTest.java new file mode 100644 index 00000000..723344f2 --- /dev/null +++ b/Kieker.WebGUI/src/test/java/kieker/webgui/common/EnvironmentLoaderListenerTest.java @@ -0,0 +1,47 @@ +/*************************************************************************** + * Copyright 2012 Kieker Project (http://kieker-monitoring.net) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ***************************************************************************/ + +package kieker.webgui.common; + +import org.junit.Assert; +import org.junit.Test; + +/** + * Test class for {@link EnvironmentLoaderListener}. + * + * @author Nils Christian Ehmke + */ +public class EnvironmentLoaderListenerTest { + + /** + * Default constructor. <b>Do not use this constructor. This is just a test class and not to be used outside a JUnit test!</b> + */ + public EnvironmentLoaderListenerTest() { + // No code necessary + } + + /** + * A test of this test class. + */ + @Test + public void testSystemPropertySet() { + final EnvironmentLoaderListener listener = new EnvironmentLoaderListener(); + Assert.assertNull("System property already set.", System.getProperty("kieker.common.logging.Log")); + listener.contextInitialized(null); + Assert.assertEquals("System property not set.", "WEBGUI", System.getProperty("kieker.common.logging.Log")); + } + +} diff --git a/Kieker.WebGUI/src/test/java/kieker/webgui/persistence/impl/util/PluginFinderTest.java b/Kieker.WebGUI/src/test/java/kieker/webgui/persistence/impl/util/PluginFinderTest.java new file mode 100644 index 00000000..66eaa8ff --- /dev/null +++ b/Kieker.WebGUI/src/test/java/kieker/webgui/persistence/impl/util/PluginFinderTest.java @@ -0,0 +1,70 @@ +/*************************************************************************** + * Copyright 2012 Kieker Project (http://kieker-monitoring.net) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ***************************************************************************/ + +package kieker.webgui.persistence.impl.util; + +import java.io.IOException; +import java.net.URL; +import java.util.List; + +import org.junit.Assert; +import org.junit.Test; + +import kieker.analysis.plugin.AbstractPlugin; +import kieker.analysis.repository.AbstractRepository; +import kieker.webgui.common.ClassAndMethodContainer; + +/** + * Test class for {@link PluginFinder}. + * + * @author Nils Christian Ehmke + */ +public class PluginFinderTest { + + private static final String KIEKER_LIB = "kieker-1.7-SNAPSHOT_emf.jar"; + + /** + * Default constructor. <b>Do not use this constructor. This is just a test class and not to be used outside a JUnit test!</b> + */ + public PluginFinderTest() { + // No code necessary + } + + /** + * A test of this test class. + */ + @Test + public void testKiekerPlugins() { + final PluginFinder pluginFinder = new PluginFinder(); + final URL kiekerURL = Thread.currentThread().getContextClassLoader().getResource(PluginFinderTest.KIEKER_LIB); + final CloseableURLClassLoader classLoader = new CloseableURLClassLoader(new URL[] { kiekerURL }, null); + final ClassAndMethodContainer classAndMethodContainer = new ClassAndMethodContainer(classLoader); + + try { + final List<Class<AbstractPlugin>> plugins = pluginFinder.getAllPluginsWithinJar(kiekerURL, classLoader, classAndMethodContainer); + final List<Class<AbstractRepository>> repositories = pluginFinder.getAllRepositoriesWithinJar(kiekerURL, classLoader, classAndMethodContainer); + + // There should be at least one element of both types + Assert.assertFalse("No plugins found.", plugins.isEmpty()); + Assert.assertFalse("No repositories found.", repositories.isEmpty()); + + classLoader.close(); + } catch (final IOException ex) { + Assert.fail("An exception occured while testing the existence of plugins and repositories."); + } + } + +} diff --git a/Kieker.WebGUI/src/test/java/kieker/webgui/web/converter/RoleStringConverterTest.java b/Kieker.WebGUI/src/test/java/kieker/webgui/web/converter/RoleStringConverterTest.java new file mode 100644 index 00000000..1b8ea30b --- /dev/null +++ b/Kieker.WebGUI/src/test/java/kieker/webgui/web/converter/RoleStringConverterTest.java @@ -0,0 +1,95 @@ +/*************************************************************************** + * Copyright 2012 Kieker Project (http://kieker-monitoring.net) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ***************************************************************************/ + +package kieker.webgui.web.converter; + +import org.junit.Assert; +import org.junit.Test; + +import kieker.webgui.domain.User.Role; + +/** + * Test class for {@link RoleStringConverter}. + * + * @author Nils Christian Ehmke + */ +public class RoleStringConverterTest { + + /** + * Default constructor. <b>Do not use this constructor. This is just a test class and not to be used outside a JUnit test!</b> + */ + public RoleStringConverterTest() { + // No code necessary + } + + /** + * A test of this test class. + */ + @Test + public void testEqualAsString() { + final RoleStringConverter converter = new RoleStringConverter(); + + Assert.assertEquals("Conversion failed.", Role.ROLE_ADMIN.toString(), converter.getAsString(null, null, Role.ROLE_ADMIN)); + Assert.assertEquals("Conversion failed.", Role.ROLE_GUEST.toString(), converter.getAsString(null, null, Role.ROLE_GUEST)); + Assert.assertEquals("Conversion failed.", Role.ROLE_USER.toString(), converter.getAsString(null, null, Role.ROLE_USER)); + } + + /** + * A test of this test class. + */ + @Test + public void testNotEqualAsString() { + final RoleStringConverter converter = new RoleStringConverter(); + + Assert.assertNotSame("Conversion failed.", Role.ROLE_ADMIN, converter.getAsString(null, null, Role.ROLE_USER)); + Assert.assertNotSame("Conversion failed.", Role.ROLE_ADMIN, converter.getAsString(null, null, Role.ROLE_GUEST)); + + Assert.assertNotSame("Conversion failed.", Role.ROLE_GUEST, converter.getAsString(null, null, Role.ROLE_ADMIN)); + Assert.assertNotSame("Conversion failed.", Role.ROLE_GUEST, converter.getAsString(null, null, Role.ROLE_USER)); + + Assert.assertNotSame("Conversion failed.", Role.ROLE_USER, converter.getAsString(null, null, Role.ROLE_GUEST)); + Assert.assertNotSame("Conversion failed.", Role.ROLE_USER, converter.getAsString(null, null, Role.ROLE_ADMIN)); + } + + /** + * A test of this test class. + */ + @Test + public void testEqualFromString() { + final RoleStringConverter converter = new RoleStringConverter(); + + Assert.assertEquals("Conversion failed.", Role.ROLE_ADMIN, converter.getAsObject(null, null, Role.ROLE_ADMIN.toString())); + Assert.assertEquals("Conversion failed.", Role.ROLE_GUEST, converter.getAsObject(null, null, Role.ROLE_GUEST.toString())); + Assert.assertEquals("Conversion failed.", Role.ROLE_USER, converter.getAsObject(null, null, Role.ROLE_USER.toString())); + } + + /** + * A test of this test class. + */ + @Test + public void testNotEqualFromString() { + final RoleStringConverter converter = new RoleStringConverter(); + + Assert.assertNotSame("Conversion failed.", Role.ROLE_ADMIN, converter.getAsObject(null, null, Role.ROLE_USER.toString())); + Assert.assertNotSame("Conversion failed.", Role.ROLE_ADMIN, converter.getAsObject(null, null, Role.ROLE_GUEST.toString())); + + Assert.assertNotSame("Conversion failed.", Role.ROLE_GUEST, converter.getAsObject(null, null, Role.ROLE_ADMIN.toString())); + Assert.assertNotSame("Conversion failed.", Role.ROLE_GUEST, converter.getAsObject(null, null, Role.ROLE_USER.toString())); + + Assert.assertNotSame("Conversion failed.", Role.ROLE_USER, converter.getAsObject(null, null, Role.ROLE_GUEST.toString())); + Assert.assertNotSame("Conversion failed.", Role.ROLE_USER, converter.getAsObject(null, null, Role.ROLE_ADMIN.toString())); + } +} -- GitLab