From 9e7e73edeccf3d24773359e0e82681511b210af7 Mon Sep 17 00:00:00 2001 From: Sebastian Struckmann Date: Thu, 16 Oct 2014 09:13:36 +0200 Subject: Sprint task - Java API - Moved initialization of ObjectMapping into constructor --- .../src/org/eclipse/jubula/client/MakeR.java | 9 +- .../src/org/eclipse/jubula/client/OM.java | 41 -------- .../org/eclipse/jubula/client/ObjectMapping.java | 32 ++++++ .../client/internal/impl/ObjectMappingImpl.java | 105 ++++++++++++++++++++ .../client/internal/impl/ObjectMappingLoader.java | 108 --------------------- .../jubula/qa/api/TestSimpleAdderRCPAUT.java | 11 ++- .../org/eclipse/jubula/qa/api/TestFactories.java | 18 ++-- 7 files changed, 161 insertions(+), 163 deletions(-) delete mode 100644 org.eclipse.jubula.client.api/src/org/eclipse/jubula/client/OM.java create mode 100644 org.eclipse.jubula.client.api/src/org/eclipse/jubula/client/ObjectMapping.java create mode 100644 org.eclipse.jubula.client.api/src/org/eclipse/jubula/client/internal/impl/ObjectMappingImpl.java delete mode 100644 org.eclipse.jubula.client.api/src/org/eclipse/jubula/client/internal/impl/ObjectMappingLoader.java diff --git a/org.eclipse.jubula.client.api/src/org/eclipse/jubula/client/MakeR.java b/org.eclipse.jubula.client.api/src/org/eclipse/jubula/client/MakeR.java index 50e8cf6f6..874ac00b7 100644 --- a/org.eclipse.jubula.client.api/src/org/eclipse/jubula/client/MakeR.java +++ b/org.eclipse.jubula.client.api/src/org/eclipse/jubula/client/MakeR.java @@ -10,8 +10,10 @@ *******************************************************************************/ package org.eclipse.jubula.client; +import java.io.InputStream; + import org.eclipse.jubula.client.internal.impl.AUTAgentImpl; -import org.eclipse.jubula.client.internal.impl.ObjectMappingLoader; +import org.eclipse.jubula.client.internal.impl.ObjectMappingImpl; /** @author BREDEX GmbH */ public final class MakeR { @@ -33,8 +35,9 @@ public final class MakeR { /** * @return a new Object Mapping instance + * @param input the input stream containing the encoded object mapping */ - public static OM createOM() { - return new ObjectMappingLoader(); + public static ObjectMapping createObjectMapping(InputStream input) { + return new ObjectMappingImpl(input); } } \ No newline at end of file diff --git a/org.eclipse.jubula.client.api/src/org/eclipse/jubula/client/OM.java b/org.eclipse.jubula.client.api/src/org/eclipse/jubula/client/OM.java deleted file mode 100644 index 5cd85e4a1..000000000 --- a/org.eclipse.jubula.client.api/src/org/eclipse/jubula/client/OM.java +++ /dev/null @@ -1,41 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2014 BREDEX GmbH. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * BREDEX GmbH - initial API and implementation and/or initial documentation - *******************************************************************************/ -package org.eclipse.jubula.client; - -import java.net.URL; - -import org.eclipse.jubula.tools.ComponentIdentifier; - -/** - * Utility class for loading object mapping associations - * - * @author BREDEX GmbH - * @created Oct 13, 2014 - */ -public interface OM { - /** - * Initializes the object mapping associations - * - * @param resourceURL - * the URL to the resource properties file - */ - public void init(URL resourceURL); - - /** - * Returns the component identifier for a component name from the cache - * - * @param compName - * the component name - * @return the component identifier or null if no identifier - * was found - */ - public ComponentIdentifier get(String compName); -} diff --git a/org.eclipse.jubula.client.api/src/org/eclipse/jubula/client/ObjectMapping.java b/org.eclipse.jubula.client.api/src/org/eclipse/jubula/client/ObjectMapping.java new file mode 100644 index 000000000..479cbb294 --- /dev/null +++ b/org.eclipse.jubula.client.api/src/org/eclipse/jubula/client/ObjectMapping.java @@ -0,0 +1,32 @@ +/******************************************************************************* + * Copyright (c) 2014 BREDEX GmbH. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * BREDEX GmbH - initial API and implementation and/or initial documentation + *******************************************************************************/ +package org.eclipse.jubula.client; + +import org.eclipse.jubula.tools.ComponentIdentifier; + +/** + * Utility class for loading object mapping associations + * + * @author BREDEX GmbH + * @created Oct 13, 2014 + */ +public interface ObjectMapping { + + /** + * Returns the component identifier for a component name from the cache + * + * @param compName + * the component name + * @return the component identifier or null if no identifier + * was found + */ + public ComponentIdentifier get(String compName); +} diff --git a/org.eclipse.jubula.client.api/src/org/eclipse/jubula/client/internal/impl/ObjectMappingImpl.java b/org.eclipse.jubula.client.api/src/org/eclipse/jubula/client/internal/impl/ObjectMappingImpl.java new file mode 100644 index 000000000..93a5c8cd6 --- /dev/null +++ b/org.eclipse.jubula.client.api/src/org/eclipse/jubula/client/internal/impl/ObjectMappingImpl.java @@ -0,0 +1,105 @@ +/******************************************************************************* + * Copyright (c) 2014 BREDEX GmbH. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * BREDEX GmbH - initial API and implementation and/or initial documentation + *******************************************************************************/ +package org.eclipse.jubula.client.internal.impl; + +import java.io.IOException; +import java.io.InputStream; +import java.util.Map; +import java.util.Properties; +import java.util.TreeMap; + +import org.eclipse.jubula.client.ObjectMapping; +import org.eclipse.jubula.client.exceptions.LoadResourceException; +import org.eclipse.jubula.client.internal.utils.SerilizationUtils; +import org.eclipse.jubula.tools.ComponentIdentifier; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Utility class for loading object mapping associations + * @author BREDEX GmbH + * @created Oct 09, 2014 + */ +public class ObjectMappingImpl implements ObjectMapping { + /** the logger */ + private static Logger log = LoggerFactory.getLogger( + ObjectMappingImpl.class); + + /** object mapping associations */ + private Properties m_objectMappingAssociations = new Properties(); + + /** object mapping associations */ + private Map m_map = + new TreeMap(); + + /** + * Utility class for loading object mapping association + * @param input the input stream containing the encoded object mapping + */ + public ObjectMappingImpl(InputStream input) { + super(); + try { + m_objectMappingAssociations.load(input); + for (Object obj : m_objectMappingAssociations.keySet()) { + if (obj instanceof String) { + String compName = (String) obj; + if (m_map.containsKey(compName)) { + log.error("There is already a mapping for the component name " //$NON-NLS-1$ + + compName); + } else { + try { + m_map.put(compName, getIdentifier(compName)); + } catch (LoadResourceException e) { + log.error(e.getLocalizedMessage(), e); + } + } + } + } + } catch (IOException e) { + log.error("Error while initialising the ObjectMappingLoader", e); //$NON-NLS-1$ + } + } + + /** {@inheritDoc} */ + public ComponentIdentifier get(String compName) { + return m_map.get(compName); + } + + /** + * Returns the component identifier for a component name + * + * @param compName + * the component name + * @return the component identifier or null if no identifier + * was found + * @throws LoadResourceException + */ + private ComponentIdentifier getIdentifier(String compName) throws + LoadResourceException { + try { + String encodedString = + m_objectMappingAssociations.getProperty(compName); + if (encodedString != null) { + Object decodedObject = SerilizationUtils.decode(encodedString); + if (decodedObject instanceof ComponentIdentifier) { + return (ComponentIdentifier) decodedObject; + } + throw new LoadResourceException("The decoded object is " //$NON-NLS-1$ + + "not of type 'IComponentIdentfier'."); //$NON-NLS-1$ + } + } catch (IOException e) { + throw new LoadResourceException("Could load the given component name", e); //$NON-NLS-1$ + } catch (ClassNotFoundException e) { + throw new LoadResourceException("Problems during deserialization...", e); //$NON-NLS-1$ + } + return null; + } +} diff --git a/org.eclipse.jubula.client.api/src/org/eclipse/jubula/client/internal/impl/ObjectMappingLoader.java b/org.eclipse.jubula.client.api/src/org/eclipse/jubula/client/internal/impl/ObjectMappingLoader.java deleted file mode 100644 index a528791c1..000000000 --- a/org.eclipse.jubula.client.api/src/org/eclipse/jubula/client/internal/impl/ObjectMappingLoader.java +++ /dev/null @@ -1,108 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2014 BREDEX GmbH. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * BREDEX GmbH - initial API and implementation and/or initial documentation - *******************************************************************************/ -package org.eclipse.jubula.client.internal.impl; - -import java.io.IOException; -import java.net.URL; -import java.util.Map; -import java.util.Properties; -import java.util.TreeMap; - -import org.eclipse.jubula.client.OM; -import org.eclipse.jubula.client.exceptions.LoadResourceException; -import org.eclipse.jubula.client.internal.utils.SerilizationUtils; -import org.eclipse.jubula.tools.ComponentIdentifier; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Utility class for loading object mapping associations - * @author BREDEX GmbH - * @created Oct 09, 2014 - */ -public class ObjectMappingLoader implements OM { - /** the logger */ - private static Logger log = LoggerFactory.getLogger( - ObjectMappingLoader.class); - - /** object mapping associations */ - private Properties m_objectMappingAssociations = new Properties(); - - /** object mapping associations */ - private Map m_map = - new TreeMap(); - - /** - * Utility class for loading object mapping association - */ - public ObjectMappingLoader() { - super(); - } - - /** {@inheritDoc} */ - public void init (URL resourceURL) { - try { - m_objectMappingAssociations.load(resourceURL.openStream()); - for (Object obj : m_objectMappingAssociations.keySet()) { - if (obj instanceof String) { - String compName = (String) obj; - if (m_map.containsKey(compName)) { - log.error("There is already a mapping for the component name " //$NON-NLS-1$ - + compName); - } else { - try { - m_map.put(compName, getIdentifier(compName)); - } catch (LoadResourceException e) { - log.error(e.getLocalizedMessage(), e); - } - } - } - } - } catch (IOException e) { - log.error("Error while initialising the ObjectMappingLoader", e); //$NON-NLS-1$ - } - } - - /** {@inheritDoc} */ - public ComponentIdentifier get(String compName) { - return m_map.get(compName); - } - - /** - * Returns the component identifier for a component name - * - * @param compName - * the component name - * @return the component identifier or null if no identifier - * was found - * @throws LoadResourceException - */ - private ComponentIdentifier getIdentifier(String compName) throws - LoadResourceException { - try { - String encodedString = - m_objectMappingAssociations.getProperty(compName); - if (encodedString != null) { - Object decodedObject = SerilizationUtils.decode(encodedString); - if (decodedObject instanceof ComponentIdentifier) { - return (ComponentIdentifier) decodedObject; - } - throw new LoadResourceException("The decoded object is " //$NON-NLS-1$ - + "not of type 'IComponentIdentfier'."); //$NON-NLS-1$ - } - } catch (IOException e) { - throw new LoadResourceException("Could load the given component name", e); //$NON-NLS-1$ - } catch (ClassNotFoundException e) { - throw new LoadResourceException("Problems during deserialization...", e); //$NON-NLS-1$ - } - return null; - } -} diff --git a/org.eclipse.jubula.qa.api/src/main/java/org/eclipse/jubula/qa/api/TestSimpleAdderRCPAUT.java b/org.eclipse.jubula.qa.api/src/main/java/org/eclipse/jubula/qa/api/TestSimpleAdderRCPAUT.java index 1c3a6485c..48ebb7aeb 100644 --- a/org.eclipse.jubula.qa.api/src/main/java/org/eclipse/jubula/qa/api/TestSimpleAdderRCPAUT.java +++ b/org.eclipse.jubula.qa.api/src/main/java/org/eclipse/jubula/qa/api/TestSimpleAdderRCPAUT.java @@ -10,12 +10,13 @@ *******************************************************************************/ package org.eclipse.jubula.qa.api; +import java.net.URL; import java.util.Locale; import org.eclipse.jubula.client.AUT; import org.eclipse.jubula.client.AUTAgent; import org.eclipse.jubula.client.MakeR; -import org.eclipse.jubula.client.OM; +import org.eclipse.jubula.client.ObjectMapping; import org.eclipse.jubula.client.exceptions.CheckFailedException; import org.eclipse.jubula.client.launch.AUTConfiguration; import org.eclipse.jubula.toolkit.base.components.GraphicsComponent; @@ -42,14 +43,14 @@ public class TestSimpleAdderRCPAUT { /** the AUT */ private AUT m_aut; /** the object mapping */ - private OM m_om; + private ObjectMapping m_om; /** prepare */ @Before public void setUp() throws Exception { - m_om = MakeR.createOM(); - m_om.init(this.getClass().getClassLoader() - .getResource("objectMapping_SimpleAdderRCP.properties")); //$NON-NLS-1$ + URL input = this.getClass().getClassLoader() + .getResource("objectMapping_SimpleAdderRCP.properties"); //$NON-NLS-1$ + m_om = MakeR.createObjectMapping(input.openStream()); m_agent = MakeR.createAUTAgent(AGENT_HOST, AGENT_PORT); m_agent.connect(); diff --git a/org.eclipse.jubula.qa.api/src/test/java/org/eclipse/jubula/qa/api/TestFactories.java b/org.eclipse.jubula.qa.api/src/test/java/org/eclipse/jubula/qa/api/TestFactories.java index 608d09f60..d960df5a2 100644 --- a/org.eclipse.jubula.qa.api/src/test/java/org/eclipse/jubula/qa/api/TestFactories.java +++ b/org.eclipse.jubula.qa.api/src/test/java/org/eclipse/jubula/qa/api/TestFactories.java @@ -1,5 +1,6 @@ package org.eclipse.jubula.qa.api; +import java.io.IOException; import java.net.URL; import junit.framework.Assert; @@ -11,7 +12,7 @@ import org.eclipse.jubula.toolkit.concrete.components.TextComponent; import org.eclipse.jubula.toolkit.concrete.components.TextInputComponent; import org.eclipse.jubula.toolkit.enums.ValueSets.Operator; import org.eclipse.jubula.client.MakeR; -import org.eclipse.jubula.client.OM; +import org.eclipse.jubula.client.ObjectMapping; import org.eclipse.jubula.tools.ComponentIdentifier; import org.junit.Test; @@ -20,19 +21,24 @@ import org.junit.Test; */ public class TestFactories { + /** the resource url */ + private URL m_resourceURL = TestFactories.class.getClassLoader() + .getResource("objectMapping_SimpleAdder.properties"); //$NON-NLS-1$ + /** object mapping loader */ - private OM m_omLoader = MakeR.createOM(); + private ObjectMapping m_omLoader; /** * test method */ @Test public void testFactories() { - - URL resourceURL = TestFactories.class.getClassLoader() - .getResource("objectMapping_SimpleAdder.properties"); //$NON-NLS-1$ - m_omLoader.init(resourceURL); + try { + m_omLoader = MakeR.createObjectMapping(m_resourceURL.openStream()); + } catch (IOException e) { + e.printStackTrace(); + } Assert.assertNotNull(m_omLoader); /** The first text field */ -- cgit v1.2.1