CAMEL-7999: More components include documentation
Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/786c6606 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/786c6606 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/786c6606 Branch: refs/heads/master Commit: 786c66062500832bb6c25f5f7381388cfe893a8d Parents: 811a980 Author: Claus Ibsen <davscl...@apache.org> Authored: Tue Jan 6 10:14:17 2015 +0100 Committer: Claus Ibsen <davscl...@apache.org> Committed: Tue Jan 6 10:32:33 2015 +0100 ---------------------------------------------------------------------- .../camel/component/jt400/Jt400Component.java | 27 +- .../component/jt400/Jt400Configuration.java | 385 ++++++++++++++++++ .../component/jt400/Jt400DataQueueConsumer.java | 23 +- .../component/jt400/Jt400DataQueueEndpoint.java | 205 ---------- .../component/jt400/Jt400DataQueueProducer.java | 17 +- .../component/jt400/Jt400DataQueueService.java | 4 +- .../camel/component/jt400/Jt400Endpoint.java | 399 +++++++++---------- .../camel/component/jt400/Jt400PgmEndpoint.java | 174 -------- .../camel/component/jt400/Jt400PgmProducer.java | 17 +- .../apache/camel/component/jt400/Jt400Type.java | 22 + ...Jt400ComponentDefaultConnectionPoolTest.java | 16 +- .../component/jt400/Jt400ComponentTest.java | 27 +- .../jt400/Jt400ConfigurationConnectionTest.java | 66 +++ .../component/jt400/Jt400ConfigurationTest.java | 67 ++++ .../jt400/Jt400CustomPollStrategyTest.java | 4 +- .../jt400/Jt400DataQueueEndpointTest.java | 53 --- .../jt400/Jt400DataQueueProducerTest.java | 4 +- .../jt400/Jt400EndpointConnectionTest.java | 66 --- .../component/jt400/Jt400EndpointTest.java | 50 +-- .../component/jt400/Jt400PgmEndpointTest.java | 17 +- 20 files changed, 814 insertions(+), 829 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/786c6606/components/camel-jt400/src/main/java/org/apache/camel/component/jt400/Jt400Component.java ---------------------------------------------------------------------- diff --git a/components/camel-jt400/src/main/java/org/apache/camel/component/jt400/Jt400Component.java b/components/camel-jt400/src/main/java/org/apache/camel/component/jt400/Jt400Component.java index 364d917..045449c 100644 --- a/components/camel-jt400/src/main/java/org/apache/camel/component/jt400/Jt400Component.java +++ b/components/camel-jt400/src/main/java/org/apache/camel/component/jt400/Jt400Component.java @@ -19,9 +19,8 @@ package org.apache.camel.component.jt400; import java.util.Map; import com.ibm.as400.access.AS400ConnectionPool; -import org.apache.camel.CamelException; import org.apache.camel.Endpoint; -import org.apache.camel.impl.DefaultComponent; +import org.apache.camel.impl.UriEndpointComponent; import org.apache.camel.util.EndpointHelper; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -31,7 +30,7 @@ import org.slf4j.LoggerFactory; * * Current implementation supports working with data queues (*DTAQ) and Program calls (*PGM) */ -public class Jt400Component extends DefaultComponent { +public class Jt400Component extends UriEndpointComponent { /** * Name of the connection pool URI option. @@ -43,9 +42,6 @@ public class Jt400Component extends DefaultComponent { */ private static final Logger LOG = LoggerFactory.getLogger(Jt400Component.class); - private static final String DATA_QUEUE = "DTAQ"; - private static final String PGM = "PGM"; - /** * Default connection pool used by the component. Note that this pool is * lazily initialized. This is because in a scenario where the user always @@ -54,9 +50,12 @@ public class Jt400Component extends DefaultComponent { */ private AS400ConnectionPool connectionPool; + public Jt400Component() { + super(Jt400Endpoint.class); + } + @Override protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> properties) throws Exception { - String type = remaining.substring(remaining.lastIndexOf(".") + 1).toUpperCase(); AS400ConnectionPool connectionPool; if (properties.containsKey(CONNECTION_POOL)) { LOG.trace("AS400ConnectionPool instance specified in the URI - will look it up."); @@ -71,15 +70,11 @@ public class Jt400Component extends DefaultComponent { connectionPool = getConnectionPool(); } - if (DATA_QUEUE.equals(type)) { - return new Jt400DataQueueEndpoint(uri, this, connectionPool); - } - - if (PGM.equals(type)) { - return new Jt400PgmEndpoint(uri, this, connectionPool); - } - - throw new CamelException(String.format("AS/400 Object type %s is not supported", type)); + String type = remaining.substring(remaining.lastIndexOf(".") + 1).toUpperCase(); + Jt400Endpoint endpoint = new Jt400Endpoint(uri, this, connectionPool); + setProperties(endpoint, properties); + endpoint.setType(Jt400Type.valueOf(type)); + return endpoint; } /** http://git-wip-us.apache.org/repos/asf/camel/blob/786c6606/components/camel-jt400/src/main/java/org/apache/camel/component/jt400/Jt400Configuration.java ---------------------------------------------------------------------- diff --git a/components/camel-jt400/src/main/java/org/apache/camel/component/jt400/Jt400Configuration.java b/components/camel-jt400/src/main/java/org/apache/camel/component/jt400/Jt400Configuration.java new file mode 100644 index 0000000..2b4ef5e --- /dev/null +++ b/components/camel-jt400/src/main/java/org/apache/camel/component/jt400/Jt400Configuration.java @@ -0,0 +1,385 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.camel.component.jt400; + +import java.beans.PropertyVetoException; +import java.net.URI; +import java.net.URISyntaxException; + +import com.ibm.as400.access.AS400; +import com.ibm.as400.access.AS400ConnectionPool; +import com.ibm.as400.access.ConnectionPoolException; +import org.apache.camel.RuntimeCamelException; +import org.apache.camel.spi.UriParam; +import org.apache.camel.spi.UriParams; +import org.apache.camel.spi.UriPath; +import org.apache.camel.util.ObjectHelper; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +@UriParams +public class Jt400Configuration { + + /** + * SearchTypes for reading from Keyed Data Queues + */ + public enum SearchType { + EQ, NE, LT, LE, GT, GE + } + + /** + * Enumeration of supported data formats + */ + public enum Format { + /** + * Using <code>String</code> for transferring data + */ + text, + + /** + * Using <code>byte[]</code> for transferring data + */ + binary + } + + /** + * Logging tool. + */ + private static final Logger LOG = LoggerFactory.getLogger(Jt400Configuration.class); + + /** + * Constant used to specify that the default system CCSID be used (a + * negative CCSID is otherwise invalid). + */ + private static final int DEFAULT_SYSTEM_CCSID = -1; + + /** + * Pool from which physical connections to the system are obtained. + */ + private final AS400ConnectionPool connectionPool; + + /** + * ID of the AS/400 user. + */ + @UriPath + private String userID; + + /** + * Password of the AS/400 user. + */ + @UriPath + private String password; + + /** + * Name of the AS/400 system. + */ + @UriPath + private String systemName; + + /** + * Fully qualified integrated file system path name of the target object of + * this endpoint (either data queue or program). + */ + @UriPath + private String objectPath; + + @UriPath + private Jt400Type type; + + /** + * CCSID to use for the connection with the AS/400 system. + */ + @UriParam + private int ccsid = DEFAULT_SYSTEM_CCSID; + + /** + * Data format for sending messages. + */ + @UriParam + private Format format = Format.text; + + /** + * Whether AS/400 prompting is enabled in the environment running Camel. + */ + @UriParam + private boolean guiAvailable; + + @UriParam + private boolean keyed; + + @UriParam + private String searchKey; + + @UriParam + private SearchType searchType = SearchType.EQ; + + @UriParam + private Integer[] outputFieldsIdxArray; + + @UriParam + private Integer[] outputFieldsLengthArray; + + public Jt400Configuration(String endpointUri, AS400ConnectionPool connectionPool) throws URISyntaxException { + ObjectHelper.notNull(endpointUri, "endpointUri", this); + ObjectHelper.notNull(connectionPool, "connectionPool", this); + + URI uri = new URI(endpointUri); + String[] credentials = uri.getUserInfo().split(":"); + systemName = uri.getHost(); + userID = credentials[0]; + password = credentials[1]; + objectPath = uri.getPath(); + + this.connectionPool = connectionPool; + } + + public Jt400Type getType() { + return type; + } + + public void setType(Jt400Type type) { + this.type = type; + } + + /** + * Returns the name of the AS/400 system. + * + * @return the name of the AS/400 system + */ + public String getSystemName() { + return systemName; + } + + public void setSystemName(String systemName) { + this.systemName = systemName; + } + + /** + * Returns the ID of the AS/400 user. + * + * @return the ID of the AS/400 user + */ + public String getUserID() { + return userID; + } + + public void setUserID(String userID) { + this.userID = userID; + } + + /** + * Returns the password of the AS/400 user. + * + * @return the password of the AS/400 user + */ + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + + /** + * Returns the fully qualified integrated file system path name of the + * target object of this endpoint. + * + * @return the fully qualified integrated file system path name of the + * target object of this endpoint + */ + public String getObjectPath() { + return objectPath; + } + + public void setObjectPath(String objectPath) { + this.objectPath = objectPath; + } + + // Options + + /** + * Returns the CCSID to use for the connection with the AS/400 system. + * Returns -1 if the CCSID to use is the default system CCSID. + * + * @return the CCSID to use for the connection with the AS/400 system, or -1 + * if that is the default system CCSID + */ + public int getCssid() { + return ccsid; + } + + /** + * Sets the CCSID to use for the connection with the AS/400 system. + * + * @param ccsid the CCSID to use for the connection with the AS/400 system + */ + public void setCcsid(int ccsid) { + this.ccsid = (ccsid < 0) ? DEFAULT_SYSTEM_CCSID : ccsid; + } + + /** + * Returns the data format for sending messages. + * + * @return the data format for sending messages + */ + public Format getFormat() { + return format; + } + + /** + * Sets the data format for sending messages. + * + * @param format the data format for sending messages + * @throws IllegalArgumentException if {@code format} is null + */ + public void setFormat(Format format) { + ObjectHelper.notNull(format, "format", this); + this.format = format; + } + + /** + * Returns whether AS/400 prompting is enabled in the environment running + * Camel. + * + * @return whether AS/400 prompting is enabled in the environment running + * Camel + */ + public boolean isGuiAvailable() { + return guiAvailable; + } + + /** + * Sets whether AS/400 prompting is enabled in the environment running + * Camel. + * + * @param guiAvailable whether AS/400 prompting is enabled in the + * environment running Camel + */ + public void setGuiAvailable(boolean guiAvailable) { + this.guiAvailable = guiAvailable; + } + + public int getCcsid() { + return ccsid; + } + + public boolean isKeyed() { + return keyed; + } + + public void setKeyed(boolean keyed) { + this.keyed = keyed; + } + + public String getSearchKey() { + return searchKey; + } + + public void setSearchKey(String searchKey) { + this.searchKey = searchKey; + } + + public SearchType getSearchType() { + return searchType; + } + + public void setSearchType(SearchType searchType) { + this.searchType = searchType; + } + + public Integer[] getOutputFieldsIdxArray() { + return outputFieldsIdxArray; + } + + public void setOutputFieldsIdxArray(Integer[] outputFieldsIdxArray) { + this.outputFieldsIdxArray = outputFieldsIdxArray; + } + + public Integer[] getOutputFieldsLengthArray() { + return outputFieldsLengthArray; + } + + public void setOutputFieldsLengthArray(Integer[] outputFieldsLengthArray) { + this.outputFieldsLengthArray = outputFieldsLengthArray; + } + + public void setOutputFieldsIdx(String outputFieldsIdx) { + if (outputFieldsIdx != null) { + String[] outputArray = outputFieldsIdx.split(","); + outputFieldsIdxArray = new Integer[outputArray.length]; + for (int i = 0; i < outputArray.length; i++) { + String str = outputArray[i]; + outputFieldsIdxArray[i] = Integer.parseInt(str); + } + } + } + + public void setFieldsLength(String fieldsLength) { + if (fieldsLength != null) { + String[] outputArray = fieldsLength.split(","); + outputFieldsLengthArray = new Integer[outputArray.length]; + for (int i = 0; i < outputArray.length; i++) { + String str = outputArray[i]; + outputFieldsLengthArray[i] = Integer.parseInt(str); + } + } + } + + // AS400 connections + + /** + * Obtains an {@code AS400} object that connects to this endpoint. Since + * these objects represent limited resources, clients have the + * responsibility of {@link #releaseConnection(AS400) releasing them} when + * done. + * + * @return an {@code AS400} object that connects to this endpoint + */ + public AS400 getConnection() { + AS400 system = null; + try { + if (LOG.isDebugEnabled()) { + LOG.debug("Getting an AS400 object for '{}' from {}.", systemName + '/' + userID, connectionPool); + } + system = connectionPool.getConnection(systemName, userID, password); + if (ccsid != DEFAULT_SYSTEM_CCSID) { + system.setCcsid(ccsid); + } + try { + system.setGuiAvailable(guiAvailable); + } catch (PropertyVetoException e) { + LOG.warn("Failed to disable AS/400 prompting in the environment running Camel. This exception will be ignored.", e); + } + return system; // Not null here. + } catch (ConnectionPoolException e) { + throw new RuntimeCamelException(String.format("Unable to obtain an AS/400 connection for system name '%s' and user ID '%s'", systemName, userID), e); + } catch (PropertyVetoException e) { + throw new RuntimeCamelException("Unable to set the CSSID to use with " + system, e); + } + } + + /** + * Releases a previously obtained {@code AS400} object from use. + * + * @param connection a previously obtained {@code AS400} object to release + */ + public void releaseConnection(AS400 connection) { + ObjectHelper.notNull(connection, "connection", this); + connectionPool.returnConnectionToPool(connection); + } + +} http://git-wip-us.apache.org/repos/asf/camel/blob/786c6606/components/camel-jt400/src/main/java/org/apache/camel/component/jt400/Jt400DataQueueConsumer.java ---------------------------------------------------------------------- diff --git a/components/camel-jt400/src/main/java/org/apache/camel/component/jt400/Jt400DataQueueConsumer.java b/components/camel-jt400/src/main/java/org/apache/camel/component/jt400/Jt400DataQueueConsumer.java index 3d7769e..2bdc7d4 100644 --- a/components/camel-jt400/src/main/java/org/apache/camel/component/jt400/Jt400DataQueueConsumer.java +++ b/components/camel-jt400/src/main/java/org/apache/camel/component/jt400/Jt400DataQueueConsumer.java @@ -23,7 +23,6 @@ import com.ibm.as400.access.KeyedDataQueue; import com.ibm.as400.access.KeyedDataQueueEntry; import org.apache.camel.Exchange; import org.apache.camel.RuntimeCamelException; -import org.apache.camel.component.jt400.Jt400DataQueueEndpoint.Format; import org.apache.camel.impl.DefaultExchange; import org.apache.camel.impl.PollingConsumerSupport; @@ -32,7 +31,7 @@ import org.apache.camel.impl.PollingConsumerSupport; */ public class Jt400DataQueueConsumer extends PollingConsumerSupport { - private final Jt400DataQueueEndpoint endpoint; + private final Jt400Endpoint endpoint; /** * Performs the lifecycle logic of this consumer. @@ -42,7 +41,7 @@ public class Jt400DataQueueConsumer extends PollingConsumerSupport { /** * Creates a new consumer instance */ - protected Jt400DataQueueConsumer(Jt400DataQueueEndpoint endpoint) { + protected Jt400DataQueueConsumer(Jt400Endpoint endpoint) { super(endpoint); this.endpoint = endpoint; this.queueService = new Jt400DataQueueService(endpoint); @@ -69,10 +68,10 @@ public class Jt400DataQueueConsumer extends PollingConsumerSupport { /** * Receives an entry from a data queue and returns an {@link Exchange} to - * send this data If the endpoint's format is set to {@link Format#binary}, + * send this data If the endpoint's format is set to {@link org.apache.camel.component.jt400.Jt400Configuration.Format#binary}, * the data queue entry's data will be received/sent as a * <code>byte[]</code>. If the endpoint's format is set to - * {@link Format#text}, the data queue entry's data will be received/sent as + * {@link org.apache.camel.component.jt400.Jt400Configuration.Format#text}, the data queue entry's data will be received/sent as * a <code>String</code>. * <p/> * The following message headers may be set by the receiver @@ -110,8 +109,8 @@ public class Jt400DataQueueConsumer extends PollingConsumerSupport { Exchange exchange = new DefaultExchange(endpoint.getCamelContext()); if (entry != null) { - exchange.getIn().setHeader(Jt400DataQueueEndpoint.SENDER_INFORMATION, entry.getSenderInformation()); - if (endpoint.getFormat() == Format.binary) { + exchange.getIn().setHeader(Jt400Endpoint.SENDER_INFORMATION, entry.getSenderInformation()); + if (endpoint.getFormat() == Jt400Configuration.Format.binary) { exchange.getIn().setBody(entry.getData()); } else { exchange.getIn().setBody(entry.getString()); @@ -136,17 +135,17 @@ public class Jt400DataQueueConsumer extends PollingConsumerSupport { Exchange exchange = new DefaultExchange(endpoint.getCamelContext()); if (entry != null) { - exchange.getIn().setHeader(Jt400DataQueueEndpoint.SENDER_INFORMATION, entry.getSenderInformation()); - if (endpoint.getFormat() == Format.binary) { + exchange.getIn().setHeader(Jt400Endpoint.SENDER_INFORMATION, entry.getSenderInformation()); + if (endpoint.getFormat() == Jt400Configuration.Format.binary) { exchange.getIn().setBody(entry.getData()); - exchange.getIn().setHeader(Jt400DataQueueEndpoint.KEY, entry.getKey()); + exchange.getIn().setHeader(Jt400Endpoint.KEY, entry.getKey()); } else { exchange.getIn().setBody(entry.getString()); - exchange.getIn().setHeader(Jt400DataQueueEndpoint.KEY, entry.getKeyString()); + exchange.getIn().setHeader(Jt400Endpoint.KEY, entry.getKeyString()); } - return exchange; } return null; } + } http://git-wip-us.apache.org/repos/asf/camel/blob/786c6606/components/camel-jt400/src/main/java/org/apache/camel/component/jt400/Jt400DataQueueEndpoint.java ---------------------------------------------------------------------- diff --git a/components/camel-jt400/src/main/java/org/apache/camel/component/jt400/Jt400DataQueueEndpoint.java b/components/camel-jt400/src/main/java/org/apache/camel/component/jt400/Jt400DataQueueEndpoint.java deleted file mode 100644 index b480c06..0000000 --- a/components/camel-jt400/src/main/java/org/apache/camel/component/jt400/Jt400DataQueueEndpoint.java +++ /dev/null @@ -1,205 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.apache.camel.component.jt400; - -import java.beans.PropertyVetoException; -import java.net.URISyntaxException; - -import com.ibm.as400.access.AS400; -import com.ibm.as400.access.AS400ConnectionPool; -import com.ibm.as400.access.BaseDataQueue; -import com.ibm.as400.access.DataQueue; -import com.ibm.as400.access.KeyedDataQueue; -import org.apache.camel.CamelException; -import org.apache.camel.PollingConsumer; -import org.apache.camel.Producer; -import org.apache.camel.impl.DefaultPollingEndpoint; -import org.apache.camel.util.ObjectHelper; -import org.apache.camel.util.URISupport; - -/** - * AS/400 Data queue endpoint - */ -public class Jt400DataQueueEndpoint extends DefaultPollingEndpoint { - - public static final String KEY = "KEY"; - public static final String SENDER_INFORMATION = "SENDER_INFORMATION"; - - /** - * SearchTypes for reading from Keyed Data Queues - */ - public enum SearchType { - EQ, NE, LT, LE, GT, GE; - } - - /** - * Enumeration of supported data formats - */ - public enum Format { - /** - * Using <code>String</code> for transferring data - */ - text, - - /** - * Using <code>byte[]</code> for transferring data - */ - binary; - } - - /** - * Encapsulates the base endpoint options and functionality. - */ - private final Jt400Endpoint baseEndpoint; - - /** - * @deprecated Used by {@link #getDataQueue()}, which is deprecated. - */ - @Deprecated - private BaseDataQueue dataQueue; - - private boolean keyed; - private String searchKey; - private SearchType searchType = SearchType.EQ; - - /** - * Creates a new AS/400 data queue endpoint using a default connection pool - * provided by the component. - * - * @throws NullPointerException if {@code component} is null - */ - protected Jt400DataQueueEndpoint(String endpointUri, Jt400Component component) throws CamelException { - this(endpointUri, component, component.getConnectionPool()); - } - - /** - * Creates a new AS/400 data queue endpoint using the specified connection - * pool. - */ - protected Jt400DataQueueEndpoint(String endpointUri, Jt400Component component, AS400ConnectionPool connectionPool) throws CamelException { - super(endpointUri, component); - ObjectHelper.notNull(connectionPool, "connectionPool"); - try { - baseEndpoint = new Jt400Endpoint(endpointUri, connectionPool); - } catch (URISyntaxException e) { - throw new CamelException("Unable to parse URI for " + URISupport.sanitizeUri(endpointUri), e); - } - } - - public void setCcsid(int ccsid) throws PropertyVetoException { - baseEndpoint.setCcsid(ccsid); - } - - public void setFormat(Format format) { - baseEndpoint.setFormat(format); - } - - public Format getFormat() { - return baseEndpoint.getFormat(); - } - - public void setKeyed(boolean keyed) { - this.keyed = keyed; - } - - public boolean isKeyed() { - return keyed; - } - - public void setSearchKey(String searchKey) { - this.searchKey = searchKey; - } - - public String getSearchKey() { - return searchKey; - } - - public void setSearchType(SearchType searchType) { - this.searchType = searchType; - } - - public SearchType getSearchType() { - return searchType; - } - - public void setGuiAvailable(boolean guiAvailable) throws PropertyVetoException { - baseEndpoint.setGuiAvailable(guiAvailable); - } - - @Override - public PollingConsumer createPollingConsumer() throws Exception { - Jt400DataQueueConsumer answer = new Jt400DataQueueConsumer(this); - configurePollingConsumer(answer); - return answer; - } - - @Override - public Producer createProducer() throws Exception { - return new Jt400DataQueueProducer(this); - } - - /** - * Obtains an {@code AS400} object that connects to this endpoint. Since - * these objects represent limited resources, clients have the - * responsibility of {@link #releaseSystem(AS400) releasing them} when done. - * - * @return an {@code AS400} object that connects to this endpoint - */ - protected AS400 getSystem() { - return baseEndpoint.getConnection(); - } - - /** - * Releases a previously obtained {@code AS400} object from use. - * - * @param system a previously obtained {@code AS400} object - */ - protected void releaseSystem(AS400 system) { - baseEndpoint.releaseConnection(system); - } - - /** - * @deprecated This method does not benefit from connection pooling; data - * queue instances should be constructed with a connection - * obtained by {@link #getSystem()}. - */ - @Deprecated - protected BaseDataQueue getDataQueue() { - if (dataQueue == null) { - AS400 system = new AS400(baseEndpoint.getSystemName(), baseEndpoint.getUserID(), baseEndpoint.getPassword()); - String objectPath = baseEndpoint.getObjectPath(); - dataQueue = keyed ? new KeyedDataQueue(system, objectPath) : new DataQueue(system, objectPath); - } - return dataQueue; - } - - /** - * Returns the fully qualified integrated file system path name of the data - * queue of this endpoint. - * - * @return the fully qualified integrated file system path name of the data - * queue of this endpoint - */ - protected String getObjectPath() { - return baseEndpoint.getObjectPath(); - } - - public boolean isSingleton() { - return false; - } - -} http://git-wip-us.apache.org/repos/asf/camel/blob/786c6606/components/camel-jt400/src/main/java/org/apache/camel/component/jt400/Jt400DataQueueProducer.java ---------------------------------------------------------------------- diff --git a/components/camel-jt400/src/main/java/org/apache/camel/component/jt400/Jt400DataQueueProducer.java b/components/camel-jt400/src/main/java/org/apache/camel/component/jt400/Jt400DataQueueProducer.java index 2133b49..c05284d 100644 --- a/components/camel-jt400/src/main/java/org/apache/camel/component/jt400/Jt400DataQueueProducer.java +++ b/components/camel-jt400/src/main/java/org/apache/camel/component/jt400/Jt400DataQueueProducer.java @@ -21,7 +21,6 @@ import com.ibm.as400.access.DataQueue; import com.ibm.as400.access.KeyedDataQueue; import org.apache.camel.Exchange; import org.apache.camel.Producer; -import org.apache.camel.component.jt400.Jt400DataQueueEndpoint.Format; import org.apache.camel.impl.DefaultProducer; /** @@ -29,14 +28,14 @@ import org.apache.camel.impl.DefaultProducer; */ public class Jt400DataQueueProducer extends DefaultProducer { - private final Jt400DataQueueEndpoint endpoint; + private final Jt400Endpoint endpoint; /** * Performs the lifecycle logic of this producer. */ private final Jt400DataQueueService queueService; - protected Jt400DataQueueProducer(Jt400DataQueueEndpoint endpoint) { + protected Jt400DataQueueProducer(Jt400Endpoint endpoint) { super(endpoint); this.endpoint = endpoint; this.queueService = new Jt400DataQueueService(endpoint); @@ -44,9 +43,9 @@ public class Jt400DataQueueProducer extends DefaultProducer { /** * Sends the {@link Exchange}'s in body to the AS/400 data queue. If the - * endpoint's format is set to {@link Format#binary}, the data queue entry's + * endpoint's format is set to {@link org.apache.camel.component.jt400.Jt400Configuration.Format#binary}, the data queue entry's * data will be sent as a <code>byte[]</code>. If the endpoint's format is - * set to {@link Format#text}, the data queue entry's data will be sent as a + * set to {@link org.apache.camel.component.jt400.Jt400Configuration.Format#text}, the data queue entry's data will be sent as a * <code>String</code>. * <p/> * If the endpoint is configured to publish to a {@link KeyedDataQueue}, @@ -62,7 +61,7 @@ public class Jt400DataQueueProducer extends DefaultProducer { } private void process(DataQueue queue, Exchange exchange) throws Exception { - if (endpoint.getFormat() == Format.binary) { + if (endpoint.getFormat() == Jt400Configuration.Format.binary) { queue.write(exchange.getIn().getBody(byte[].class)); } else { queue.write(exchange.getIn().getBody(String.class)); @@ -70,10 +69,10 @@ public class Jt400DataQueueProducer extends DefaultProducer { } private void process(KeyedDataQueue queue, Exchange exchange) throws Exception { - if (endpoint.getFormat() == Format.binary) { - queue.write(exchange.getIn().getHeader(Jt400DataQueueEndpoint.KEY, byte[].class), exchange.getIn().getBody(byte[].class)); + if (endpoint.getFormat() == Jt400Configuration.Format.binary) { + queue.write(exchange.getIn().getHeader(Jt400Endpoint.KEY, byte[].class), exchange.getIn().getBody(byte[].class)); } else { - queue.write(exchange.getIn().getHeader(Jt400DataQueueEndpoint.KEY, String.class), exchange.getIn().getBody(String.class)); + queue.write(exchange.getIn().getHeader(Jt400Endpoint.KEY, String.class), exchange.getIn().getBody(String.class)); } } http://git-wip-us.apache.org/repos/asf/camel/blob/786c6606/components/camel-jt400/src/main/java/org/apache/camel/component/jt400/Jt400DataQueueService.java ---------------------------------------------------------------------- diff --git a/components/camel-jt400/src/main/java/org/apache/camel/component/jt400/Jt400DataQueueService.java b/components/camel-jt400/src/main/java/org/apache/camel/component/jt400/Jt400DataQueueService.java index 17ec991..bd984c3 100644 --- a/components/camel-jt400/src/main/java/org/apache/camel/component/jt400/Jt400DataQueueService.java +++ b/components/camel-jt400/src/main/java/org/apache/camel/component/jt400/Jt400DataQueueService.java @@ -39,7 +39,7 @@ class Jt400DataQueueService implements Service { /** * Endpoint which this service connects to. */ - private final Jt400DataQueueEndpoint endpoint; + private final Jt400Endpoint endpoint; /** * Data queue object that corresponds to the endpoint of this service (null if stopped). @@ -52,7 +52,7 @@ class Jt400DataQueueService implements Service { * * @param endpoint endpoint which this service connects to */ - Jt400DataQueueService(Jt400DataQueueEndpoint endpoint) { + Jt400DataQueueService(Jt400Endpoint endpoint) { ObjectHelper.notNull(endpoint, "endpoint", this); this.endpoint = endpoint; } http://git-wip-us.apache.org/repos/asf/camel/blob/786c6606/components/camel-jt400/src/main/java/org/apache/camel/component/jt400/Jt400Endpoint.java ---------------------------------------------------------------------- diff --git a/components/camel-jt400/src/main/java/org/apache/camel/component/jt400/Jt400Endpoint.java b/components/camel-jt400/src/main/java/org/apache/camel/component/jt400/Jt400Endpoint.java index cc01c78..c9b522d 100644 --- a/components/camel-jt400/src/main/java/org/apache/camel/component/jt400/Jt400Endpoint.java +++ b/components/camel-jt400/src/main/java/org/apache/camel/component/jt400/Jt400Endpoint.java @@ -16,249 +16,234 @@ */ package org.apache.camel.component.jt400; -import java.beans.PropertyVetoException; -import java.net.URI; import java.net.URISyntaxException; +import java.util.Arrays; +import javax.naming.OperationNotSupportedException; import com.ibm.as400.access.AS400; import com.ibm.as400.access.AS400ConnectionPool; -import com.ibm.as400.access.ConnectionPoolException; -import org.apache.camel.RuntimeCamelException; -import org.apache.camel.component.jt400.Jt400DataQueueEndpoint.Format; +import org.apache.camel.CamelException; +import org.apache.camel.Consumer; +import org.apache.camel.PollingConsumer; +import org.apache.camel.Processor; +import org.apache.camel.Producer; +import org.apache.camel.impl.DefaultPollingEndpoint; +import org.apache.camel.spi.UriEndpoint; +import org.apache.camel.spi.UriParam; import org.apache.camel.util.ObjectHelper; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import org.apache.camel.util.URISupport; -/** - * Pseudo-abstract base JT400 endpoint. This class provides the options that - * supported by both the {@link Jt400DataQueueEndpoint} and - * {@link Jt400PgmEndpoint}, and also serves as a factory of connections to the - * system. - */ -class Jt400Endpoint { - - /** - * Logging tool. - */ - private static final Logger LOG = LoggerFactory.getLogger(Jt400Endpoint.class); +@UriEndpoint(scheme = "jt400", consumerClass = Jt400DataQueueConsumer.class, label = "messaging") +public class Jt400Endpoint extends DefaultPollingEndpoint { + + public static final String KEY = "KEY"; + public static final String SENDER_INFORMATION = "SENDER_INFORMATION"; + + @UriParam + private final Jt400Configuration configuration; /** - * Constant used to specify that the default system CCSID be used (a - * negative CCSID is otherwise invalid). - */ - private static final int DEFAULT_SYSTEM_CCSID = -1; - - /** - * Name of the AS/400 system. - */ - private final String systemName; - - /** - * ID of the AS/400 user. - */ - private final String userID; - - /** - * Password of the AS/400 user. - */ - private final String password; - - /** - * Fully qualified integrated file system path name of the target object of - * this endpoint (either data queue or program). - */ - private final String objectPath; - - /** - * Pool from which physical connections to the system are obtained. - */ - private final AS400ConnectionPool connectionPool; - - /** - * CCSID to use for the connection with the AS/400 system. - */ - private int ccsid = DEFAULT_SYSTEM_CCSID; - - /** - * Data format for sending messages. - */ - private Format format = Format.text; - - /** - * Whether AS/400 prompting is enabled in the environment running Camel. - */ - private boolean guiAvailable; - - /** - * Creates a new endpoint instance for the specified URI, which will use the - * specified pool for obtaining physical connections to the system. + * Creates a new AS/400 data queue endpoint using a default connection pool + * provided by the component. * - * @param endpointUri URI of the endpoint - * @param connectionPool pool for obtaining physical connections to the - * system - * @throws URISyntaxException if unable to parse {@code endpointUri} - * @throws IllegalArgumentException if either {@code endpointUri} or - * {@code connectionPool} are null + * @throws NullPointerException if {@code component} is null */ - Jt400Endpoint(String endpointUri, AS400ConnectionPool connectionPool) throws URISyntaxException { - ObjectHelper.notNull(endpointUri, "endpointUri", this); - ObjectHelper.notNull(connectionPool, "connectionPool", this); - - URI uri = new URI(endpointUri); - String[] credentials = uri.getUserInfo().split(":"); - systemName = uri.getHost(); - userID = credentials[0]; - password = credentials[1]; - objectPath = uri.getPath(); - - this.connectionPool = connectionPool; + protected Jt400Endpoint(String endpointUri, Jt400Component component) throws CamelException { + this(endpointUri, component, component.getConnectionPool()); } - + /** - * Returns the name of the AS/400 system. - * - * @return the name of the AS/400 system + * Creates a new AS/400 data queue endpoint using the specified connection + * pool. */ - public String getSystemName() { - return systemName; + protected Jt400Endpoint(String endpointUri, Jt400Component component, AS400ConnectionPool connectionPool) throws CamelException { + super(endpointUri, component); + ObjectHelper.notNull(connectionPool, "connectionPool"); + try { + configuration = new Jt400Configuration(endpointUri, connectionPool); + } catch (URISyntaxException e) { + throw new CamelException("Unable to parse URI for " + URISupport.sanitizeUri(endpointUri), e); + } } - - /** - * Returns the ID of the AS/400 user. - * - * @return the ID of the AS/400 user - */ - public String getUserID() { - return userID; + + @Override + public PollingConsumer createPollingConsumer() throws Exception { + Jt400DataQueueConsumer answer = new Jt400DataQueueConsumer(this); + configurePollingConsumer(answer); + return answer; } - - /** - * Returns the password of the AS/400 user. - * - * @return the password of the AS/400 user - */ - public String getPassword() { - return password; + + @Override + public Producer createProducer() throws Exception { + if (Jt400Type.DTAQ == configuration.getType()) { + return new Jt400DataQueueProducer(this); + } else { + return new Jt400PgmProducer(this); + } } - - /** - * Returns the fully qualified integrated file system path name of the - * target object of this endpoint. - * - * @return the fully qualified integrated file system path name of the - * target object of this endpoint - */ - public String getObjectPath() { - return objectPath; + + @Override + public Consumer createConsumer(Processor processor) throws Exception { + if (Jt400Type.DTAQ == configuration.getType()) { + return new Jt400DataQueueConsumer(this); + } else { + throw new OperationNotSupportedException(); + } } - - - // Options - - /** - * Returns the CCSID to use for the connection with the AS/400 system. - * Returns -1 if the CCSID to use is the default system CCSID. - * - * @return the CCSID to use for the connection with the AS/400 system, or -1 - * if that is the default system CCSID - */ - public int getCssid() { - return ccsid; + + public boolean isSingleton() { + // cannot be singleton as we store an AS400 instance on the configuration + return false; } - + /** - * Sets the CCSID to use for the connection with the AS/400 system. + * Obtains an {@code AS400} object that connects to this endpoint. Since + * these objects represent limited resources, clients have the + * responsibility of {@link #releaseSystem(AS400) releasing them} when done. * - * @param ccsid the CCSID to use for the connection with the AS/400 system + * @return an {@code AS400} object that connects to this endpoint */ - public void setCcsid(int ccsid) { - this.ccsid = (ccsid < 0) ? DEFAULT_SYSTEM_CCSID : ccsid; + protected AS400 getSystem() { + return configuration.getConnection(); } /** - * Returns the data format for sending messages. + * Releases a previously obtained {@code AS400} object from use. * - * @return the data format for sending messages + * @param system a previously obtained {@code AS400} object */ - public Format getFormat() { - return format; + protected void releaseSystem(AS400 system) { + configuration.releaseConnection(system); } - + /** - * Sets the data format for sending messages. + * Returns the fully qualified integrated file system path name of the data + * queue of this endpoint. * - * @param format the data format for sending messages - * @throws IllegalArgumentException if {@code format} is null + * @return the fully qualified integrated file system path name of the data + * queue of this endpoint */ - public void setFormat(Format format) { - ObjectHelper.notNull(format, "format", this); - this.format = format; + protected String getObjectPath() { + return configuration.getObjectPath(); } - - /** - * Returns whether AS/400 prompting is enabled in the environment running - * Camel. - * - * @return whether AS/400 prompting is enabled in the environment running - * Camel - */ + + public Jt400Type getType() { + return configuration.getType(); + } + + public void setType(Jt400Type type) { + configuration.setType(type); + } + + public String getSearchKey() { + return configuration.getSearchKey(); + } + + public boolean isKeyed() { + return configuration.isKeyed(); + } + + public Integer[] getOutputFieldsIdxArray() { + return configuration.getOutputFieldsIdxArray(); + } + + public int getCcsid() { + return configuration.getCcsid(); + } + + public void setOutputFieldsIdxArray(Integer[] outputFieldsIdxArray) { + configuration.setOutputFieldsIdxArray(outputFieldsIdxArray); + } + + public void setSearchKey(String searchKey) { + configuration.setSearchKey(searchKey); + } + + public void setOutputFieldsIdx(String outputFieldsIdx) { + configuration.setOutputFieldsIdx(outputFieldsIdx); + } + + public void setKeyed(boolean keyed) { + configuration.setKeyed(keyed); + } + + public Integer[] getOutputFieldsLengthArray() { + return configuration.getOutputFieldsLengthArray(); + } + + public void setSearchType(Jt400Configuration.SearchType searchType) { + configuration.setSearchType(searchType); + } + public boolean isGuiAvailable() { - return guiAvailable; + return configuration.isGuiAvailable(); } - - /** - * Sets whether AS/400 prompting is enabled in the environment running - * Camel. - * - * @param guiAvailable whether AS/400 prompting is enabled in the - * environment running Camel - */ + + public void setFormat(Jt400Configuration.Format format) { + configuration.setFormat(format); + } + + public void setFieldsLength(String fieldsLength) { + configuration.setFieldsLength(fieldsLength); + } + + public Jt400Configuration.Format getFormat() { + return configuration.getFormat(); + } + + public void setOutputFieldsLengthArray(Integer[] outputFieldsLengthArray) { + configuration.setOutputFieldsLengthArray(outputFieldsLengthArray); + } + + public int getCssid() { + return configuration.getCssid(); + } + + public String getUserID() { + return configuration.getUserID(); + } + + public Jt400Configuration.SearchType getSearchType() { + return configuration.getSearchType(); + } + + public void setCcsid(int ccsid) { + configuration.setCcsid(ccsid); + } + public void setGuiAvailable(boolean guiAvailable) { - this.guiAvailable = guiAvailable; + configuration.setGuiAvailable(guiAvailable); } - - - // AS400 connections - - /** - * Obtains an {@code AS400} object that connects to this endpoint. Since - * these objects represent limited resources, clients have the - * responsibility of {@link #releaseConnection(AS400) releasing them} when - * done. - * - * @return an {@code AS400} object that connects to this endpoint - */ - public AS400 getConnection() { - AS400 system = null; - try { - if (LOG.isDebugEnabled()) { - LOG.debug("Getting an AS400 object for '{}' from {}.", systemName + '/' + userID, connectionPool); - } - system = connectionPool.getConnection(systemName, userID, password); - if (ccsid != DEFAULT_SYSTEM_CCSID) { - system.setCcsid(ccsid); - } - try { - system.setGuiAvailable(guiAvailable); - } catch (PropertyVetoException e) { - LOG.warn("Failed to disable AS/400 prompting in the environment running Camel. This exception will be ignored.", e); - } - return system; // Not null here. - } catch (ConnectionPoolException e) { - throw new RuntimeCamelException(String.format("Unable to obtain an AS/400 connection for system name '%s' and user ID '%s'", systemName, userID), e); - } catch (PropertyVetoException e) { - throw new RuntimeCamelException("Unable to set the CSSID to use with " + system, e); - } + + public String getPassword() { + return configuration.getPassword(); } - - /** - * Releases a previously obtained {@code AS400} object from use. - * - * @param connection a previously obtained {@code AS400} object to release - */ - public void releaseConnection(AS400 connection) { - ObjectHelper.notNull(connection, "connection", this); - connectionPool.returnConnectionToPool(connection); + + public String getSystemName() { + return configuration.getSystemName(); + } + + public boolean isFieldIdxForOuput(int idx) { + return Arrays.binarySearch(getOutputFieldsIdxArray(), idx) >= 0; + } + + public int getOutputFieldLength(int idx) { + return configuration.getOutputFieldsLengthArray()[idx]; + } + + public void setObjectPath(String objectPath) { + configuration.setObjectPath(objectPath); } + public void setPassword(String password) { + configuration.setPassword(password); + } + + public void setUserID(String userID) { + configuration.setUserID(userID); + } + + public void setSystemName(String systemName) { + configuration.setSystemName(systemName); + } } http://git-wip-us.apache.org/repos/asf/camel/blob/786c6606/components/camel-jt400/src/main/java/org/apache/camel/component/jt400/Jt400PgmEndpoint.java ---------------------------------------------------------------------- diff --git a/components/camel-jt400/src/main/java/org/apache/camel/component/jt400/Jt400PgmEndpoint.java b/components/camel-jt400/src/main/java/org/apache/camel/component/jt400/Jt400PgmEndpoint.java deleted file mode 100644 index 2b89952..0000000 --- a/components/camel-jt400/src/main/java/org/apache/camel/component/jt400/Jt400PgmEndpoint.java +++ /dev/null @@ -1,174 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.apache.camel.component.jt400; - -import java.beans.PropertyVetoException; -import java.net.URISyntaxException; -import java.util.Arrays; -import java.util.Map; -import javax.naming.OperationNotSupportedException; - -import com.ibm.as400.access.AS400; -import com.ibm.as400.access.AS400ConnectionPool; -import org.apache.camel.CamelContext; -import org.apache.camel.CamelException; -import org.apache.camel.Consumer; -import org.apache.camel.Processor; -import org.apache.camel.Producer; -import org.apache.camel.RuntimeCamelException; -import org.apache.camel.component.jt400.Jt400DataQueueEndpoint.Format; -import org.apache.camel.impl.DefaultEndpoint; -import org.apache.camel.util.EndpointHelper; -import org.apache.camel.util.ObjectHelper; -import org.apache.camel.util.URISupport; - -public class Jt400PgmEndpoint extends DefaultEndpoint { - /** - * Encapsulates the base endpoint options and functionality. - */ - private final Jt400Endpoint baseEndpoint; - - private Integer[] outputFieldsIdxArray; - private Integer[] outputFieldsLengthArray; - - /** - * Creates a new AS/400 PGM CALL endpoint using a default connection pool - * provided by the component. - * - * @throws NullPointerException if {@code component} is null - */ - protected Jt400PgmEndpoint(String endpointUri, Jt400Component component) throws CamelException { - this(endpointUri, component, component.getConnectionPool()); - } - - /** - * Creates a new AS/400 PGM CALL endpoint using the specified connection - * pool. - */ - protected Jt400PgmEndpoint(String endpointUri, Jt400Component component, AS400ConnectionPool connectionPool) throws CamelException { - super(endpointUri, component); - ObjectHelper.notNull(connectionPool, "connectionPool"); - try { - baseEndpoint = new Jt400Endpoint(endpointUri, connectionPool); - } catch (URISyntaxException e) { - throw new CamelException("Unable to parse URI for " + URISupport.sanitizeUri(endpointUri), e); - } - } - - @SuppressWarnings("deprecation") - public Jt400PgmEndpoint(String endpointUri, String programToExecute, Map<String, Object> parameters, - CamelContext camelContext) { - super(endpointUri, camelContext); - ObjectHelper.notNull(parameters, "parameters", this); - if (!parameters.containsKey(Jt400Component.CONNECTION_POOL)) { - throw new RuntimeCamelException(String.format("parameters must specify '%s'", Jt400Component.CONNECTION_POOL)); - } - String poolId = parameters.get(Jt400Component.CONNECTION_POOL).toString(); - AS400ConnectionPool connectionPool = EndpointHelper.resolveReferenceParameter(camelContext, poolId, AS400ConnectionPool.class, true); - try { - this.baseEndpoint = new Jt400Endpoint(endpointUri, connectionPool); - } catch (URISyntaxException e) { - throw new RuntimeCamelException("Unable to parse URI for " + endpointUri, e); - } - } - - public Producer createProducer() throws Exception { - return new Jt400PgmProducer(this); - } - - public Consumer createConsumer(Processor processor) throws Exception { - throw new OperationNotSupportedException(); - } - - public boolean isSingleton() { - // cannot be singleton as we store an AS400 instance on this endpoint - return false; - } - - public boolean isFieldIdxForOuput(int idx) { - return Arrays.binarySearch(outputFieldsIdxArray, idx) >= 0; - } - - public int getOutputFieldLength(int idx) { - return outputFieldsLengthArray[idx]; - } - - // getters and setters - public String getProgramToExecute() { - return baseEndpoint.getObjectPath(); - } - - /** - * Obtains an {@code AS400} object that connects to this endpoint. Since - * these objects represent limited resources, clients have the - * responsibility of {@link #releaseiSeries(AS400) releasing them} when - * done. - * - * @return an {@code AS400} object that connects to this endpoint - */ - public AS400 getiSeries() { - return baseEndpoint.getConnection(); - } - - /** - * Releases a previously obtained {@code AS400} object from use. - * - * @param iSeries a previously obtained {@code AS400} object - */ - public void releaseiSeries(AS400 iSeries) { - baseEndpoint.releaseConnection(iSeries); - } - - public void setOutputFieldsIdx(String outputFieldsIdx) { - if (outputFieldsIdx != null) { - String[] outputArray = outputFieldsIdx.split(","); - outputFieldsIdxArray = new Integer[outputArray.length]; - for (int i = 0; i < outputArray.length; i++) { - String str = outputArray[i]; - outputFieldsIdxArray[i] = Integer.parseInt(str); - } - } - } - - public void setFieldsLength(String fieldsLength) { - if (fieldsLength != null) { - String[] outputArray = fieldsLength.split(","); - outputFieldsLengthArray = new Integer[outputArray.length]; - for (int i = 0; i < outputArray.length; i++) { - String str = outputArray[i]; - outputFieldsLengthArray[i] = Integer.parseInt(str); - } - } - } - - public void setFormat(Format format) { - baseEndpoint.setFormat(format); - } - - public Format getFormat() { - return baseEndpoint.getFormat(); - } - - public void setGuiAvailable(boolean guiAvailable) throws PropertyVetoException { - baseEndpoint.setGuiAvailable(guiAvailable); - } - - public boolean isGuiAvailable() { - return baseEndpoint.isGuiAvailable(); - } - -} http://git-wip-us.apache.org/repos/asf/camel/blob/786c6606/components/camel-jt400/src/main/java/org/apache/camel/component/jt400/Jt400PgmProducer.java ---------------------------------------------------------------------- diff --git a/components/camel-jt400/src/main/java/org/apache/camel/component/jt400/Jt400PgmProducer.java b/components/camel-jt400/src/main/java/org/apache/camel/component/jt400/Jt400PgmProducer.java index 0c0909c..620fb46 100644 --- a/components/camel-jt400/src/main/java/org/apache/camel/component/jt400/Jt400PgmProducer.java +++ b/components/camel-jt400/src/main/java/org/apache/camel/component/jt400/Jt400PgmProducer.java @@ -29,7 +29,6 @@ import com.ibm.as400.access.ProgramCall; import com.ibm.as400.access.ProgramParameter; import org.apache.camel.Exchange; import org.apache.camel.InvalidPayloadException; -import org.apache.camel.component.jt400.Jt400DataQueueEndpoint.Format; import org.apache.camel.impl.DefaultProducer; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -40,17 +39,17 @@ public class Jt400PgmProducer extends DefaultProducer { private AS400 iSeries; - public Jt400PgmProducer(Jt400PgmEndpoint endpoint) { + public Jt400PgmProducer(Jt400Endpoint endpoint) { super(endpoint); } - private Jt400PgmEndpoint getISeriesEndpoint() { - return (Jt400PgmEndpoint) super.getEndpoint(); + private Jt400Endpoint getISeriesEndpoint() { + return (Jt400Endpoint) super.getEndpoint(); } public void process(Exchange exchange) throws Exception { - String commandStr = getISeriesEndpoint().getProgramToExecute(); + String commandStr = getISeriesEndpoint().getObjectPath(); ProgramParameter[] parameterList = getParameterList(exchange); ProgramCall pgmCall = new ProgramCall(iSeries); @@ -103,7 +102,7 @@ public class Jt400PgmProducer extends DefaultProducer { if (input) { if (param != null) { AS400DataType typeConverter; - if (getISeriesEndpoint().getFormat() == Format.binary) { + if (getISeriesEndpoint().getFormat() == Jt400Configuration.Format.binary) { typeConverter = new AS400ByteArray(length); } else { typeConverter = new AS400Text(length, iSeries); @@ -150,7 +149,7 @@ public class Jt400PgmProducer extends DefaultProducer { if (output != null) { int length = pgmParam.getOutputDataLength(); AS400DataType typeConverter; - if (getISeriesEndpoint().getFormat() == Format.binary) { + if (getISeriesEndpoint().getFormat() == Jt400Configuration.Format.binary) { typeConverter = new AS400ByteArray(length); } else { typeConverter = new AS400Text(length, iSeries); @@ -187,7 +186,7 @@ public class Jt400PgmProducer extends DefaultProducer { @Override protected void doStart() throws Exception { if (iSeries == null) { - iSeries = getISeriesEndpoint().getiSeries(); + iSeries = getISeriesEndpoint().getSystem(); } if (!iSeries.isConnected(AS400.COMMAND)) { LOG.info("Connecting to {}", getISeriesEndpoint()); @@ -199,7 +198,7 @@ public class Jt400PgmProducer extends DefaultProducer { protected void doStop() throws Exception { if (iSeries != null) { LOG.info("Releasing connection to {}", getISeriesEndpoint()); - getISeriesEndpoint().releaseiSeries(iSeries); + getISeriesEndpoint().releaseSystem(iSeries); iSeries = null; } } http://git-wip-us.apache.org/repos/asf/camel/blob/786c6606/components/camel-jt400/src/main/java/org/apache/camel/component/jt400/Jt400Type.java ---------------------------------------------------------------------- diff --git a/components/camel-jt400/src/main/java/org/apache/camel/component/jt400/Jt400Type.java b/components/camel-jt400/src/main/java/org/apache/camel/component/jt400/Jt400Type.java new file mode 100644 index 0000000..b5a3b77 --- /dev/null +++ b/components/camel-jt400/src/main/java/org/apache/camel/component/jt400/Jt400Type.java @@ -0,0 +1,22 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.camel.component.jt400; + +public enum Jt400Type { + + DTAQ, PGM +} http://git-wip-us.apache.org/repos/asf/camel/blob/786c6606/components/camel-jt400/src/test/java/org/apache/camel/component/jt400/Jt400ComponentDefaultConnectionPoolTest.java ---------------------------------------------------------------------- diff --git a/components/camel-jt400/src/test/java/org/apache/camel/component/jt400/Jt400ComponentDefaultConnectionPoolTest.java b/components/camel-jt400/src/test/java/org/apache/camel/component/jt400/Jt400ComponentDefaultConnectionPoolTest.java index 2cba2a0..17bf83c 100644 --- a/components/camel-jt400/src/test/java/org/apache/camel/component/jt400/Jt400ComponentDefaultConnectionPoolTest.java +++ b/components/camel-jt400/src/test/java/org/apache/camel/component/jt400/Jt400ComponentDefaultConnectionPoolTest.java @@ -16,32 +16,26 @@ */ package org.apache.camel.component.jt400; -import java.util.HashMap; - import com.ibm.as400.access.AS400ConnectionPool; -import org.apache.camel.CamelException; import org.junit.After; import org.junit.Assert; import org.junit.Before; import org.junit.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -public class Jt400ComponentDefaultConnectionPoolTest { +public class Jt400ComponentDefaultConnectionPoolTest extends Jt400TestSupport { private Jt400Component component; @Before public void setUp() throws Exception { + super.setUp(); component = new Jt400Component(); + component.setCamelContext(context); try { // Use an invalid object type so that endpoints are never created // and actual connections are never requested - component.createEndpoint("jt400://user:password@host/qsys.lib/library.lib/program.xxx", - "/user:password@host/qsys.lib/library.lib/program.xxx", - new HashMap<String, Object>(0)); + component.createEndpoint("jt400://user:password@host/qsys.lib/library.lib/program.xxx"); Assert.fail("Should have thrown exception"); - } catch (CamelException e) { + } catch (Exception e) { /* Expected */ } } http://git-wip-us.apache.org/repos/asf/camel/blob/786c6606/components/camel-jt400/src/test/java/org/apache/camel/component/jt400/Jt400ComponentTest.java ---------------------------------------------------------------------- diff --git a/components/camel-jt400/src/test/java/org/apache/camel/component/jt400/Jt400ComponentTest.java b/components/camel-jt400/src/test/java/org/apache/camel/component/jt400/Jt400ComponentTest.java index d419b21..29bb4db 100644 --- a/components/camel-jt400/src/test/java/org/apache/camel/component/jt400/Jt400ComponentTest.java +++ b/components/camel-jt400/src/test/java/org/apache/camel/component/jt400/Jt400ComponentTest.java @@ -16,10 +16,6 @@ */ package org.apache.camel.component.jt400; -import java.util.HashMap; -import java.util.Map; - -import org.apache.camel.CamelException; import org.apache.camel.Endpoint; import org.junit.Before; import org.junit.Test; @@ -30,7 +26,6 @@ import org.junit.Test; public class Jt400ComponentTest extends Jt400TestSupport { private Jt400Component component; - private Map<String, Object> properties; @Override @Before @@ -39,33 +34,28 @@ public class Jt400ComponentTest extends Jt400TestSupport { component = new Jt400Component(); component.setCamelContext(context()); - - properties = new HashMap<String, Object>(); - properties.put("connectionPool", "#mockPool"); } /** - * Test creation of a {@link Jt400DataQueueEndpoint} for Datq + * Test creation of a {@link Jt400Endpoint} for Datq */ @Test public void testCreateDatqEndpoint() throws Exception { Endpoint endpoint = component - .createEndpoint("jt400://user:password@host/qsys.lib/library.lib/queue.dtaq", - "/user:password@host/qsys.lib/library.lib/queue.dtaq", properties); + .createEndpoint("jt400://user:password@host/qsys.lib/library.lib/queue.dtaq?connectionPool=#mockPool"); assertNotNull(endpoint); - assertTrue(endpoint instanceof Jt400DataQueueEndpoint); + assertTrue(endpoint instanceof Jt400Endpoint); } /** - * Test creation of a {@link Jt400DataQueueEndpoint} for pgm calls + * Test creation of a {@link Jt400Endpoint} for pgm calls */ @Test public void testCreatePgmEndpoint() throws Exception { Endpoint endpoint = component - .createEndpoint("jt400://user:password@host/qsys.lib/library.lib/queue.pgm", - "/user:password@host/qsys.lib/library.lib/queue.pgm", properties); + .createEndpoint("jt400://user:password@host/qsys.lib/library.lib/queue.pgm?connectionPool=#mockPool"); assertNotNull(endpoint); - assertTrue(endpoint instanceof Jt400PgmEndpoint); + assertTrue(endpoint instanceof Jt400Endpoint); } /** @@ -74,10 +64,9 @@ public class Jt400ComponentTest extends Jt400TestSupport { @Test public void testCreateEndpointForOtherObjectType() throws Exception { try { - component.createEndpoint("jt400://user:password@host/qsys.lib/library.lib/program.xxx", - "/user:password@host/qsys.lib/library.lib/program.xxx", new HashMap<String, Object>()); + component.createEndpoint("jt400://user:password@host/qsys.lib/library.lib/program.xxx"); fail("Exception should been thrown when trying to create an endpoint for an unsupported object type"); - } catch (CamelException e) { + } catch (Exception e) { // this is just what we expected } } http://git-wip-us.apache.org/repos/asf/camel/blob/786c6606/components/camel-jt400/src/test/java/org/apache/camel/component/jt400/Jt400ConfigurationConnectionTest.java ---------------------------------------------------------------------- diff --git a/components/camel-jt400/src/test/java/org/apache/camel/component/jt400/Jt400ConfigurationConnectionTest.java b/components/camel-jt400/src/test/java/org/apache/camel/component/jt400/Jt400ConfigurationConnectionTest.java new file mode 100644 index 0000000..6b42215 --- /dev/null +++ b/components/camel-jt400/src/test/java/org/apache/camel/component/jt400/Jt400ConfigurationConnectionTest.java @@ -0,0 +1,66 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.camel.component.jt400; + +import com.ibm.as400.access.AS400; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +public class Jt400ConfigurationConnectionTest extends Jt400TestSupport { + + private Jt400Configuration jt400Configuration; + private AS400 connection; + + @Before + public void setUp() throws Exception { + super.setUp(); + + jt400Configuration = new Jt400Configuration("jt400://USER:password@host/QSYS.LIB/LIBRARY.LIB/QUEUE.DTAQ", getConnectionPool()); + jt400Configuration.setCcsid(37); + connection = jt400Configuration.getConnection(); + } + + @After + public void tearDown() throws Exception { + if (connection != null) { + jt400Configuration.releaseConnection(connection); + } + super.tearDown(); + } + + @Test + public void testSystemName() { + assertEquals("host", connection.getSystemName()); + } + + @Test + public void testUserId() { + assertEquals("USER", connection.getUserId()); + } + + @Test + public void testCssid() { + assertEquals(37, connection.getCcsid()); + } + + @Test + public void testGuiAvailable() { + assertFalse(connection.isGuiAvailable()); + } + +} http://git-wip-us.apache.org/repos/asf/camel/blob/786c6606/components/camel-jt400/src/test/java/org/apache/camel/component/jt400/Jt400ConfigurationTest.java ---------------------------------------------------------------------- diff --git a/components/camel-jt400/src/test/java/org/apache/camel/component/jt400/Jt400ConfigurationTest.java b/components/camel-jt400/src/test/java/org/apache/camel/component/jt400/Jt400ConfigurationTest.java new file mode 100644 index 0000000..523628a --- /dev/null +++ b/components/camel-jt400/src/test/java/org/apache/camel/component/jt400/Jt400ConfigurationTest.java @@ -0,0 +1,67 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.camel.component.jt400; + +import org.junit.Before; +import org.junit.Test; + +public class Jt400ConfigurationTest extends Jt400TestSupport { + + private Jt400Configuration jt400Configuration; + + @Before + public void setUp() throws Exception { + super.setUp(); + jt400Configuration = new Jt400Configuration("jt400://USER:password@host/QSYS.LIB/LIBRARY.LIB/QUEUE.DTAQ", getConnectionPool()); + } + + @Test + public void testSystemName() { + assertEquals("host", jt400Configuration.getSystemName()); + } + + @Test + public void testUserID() { + assertEquals("USER", jt400Configuration.getUserID()); + } + + @Test + public void testPassword() { + assertEquals("password", jt400Configuration.getPassword()); + } + + @Test + public void testObjectPath() { + assertEquals("/QSYS.LIB/LIBRARY.LIB/QUEUE.DTAQ", jt400Configuration.getObjectPath()); + } + + @Test + public void testDefaultCcsid() { + assertEquals(-1, jt400Configuration.getCssid()); + } + + @Test + public void testDefaultFormat() { + assertEquals(Jt400Configuration.Format.text, jt400Configuration.getFormat()); + } + + @Test + public void testDefaultGuiAvailable() { + assertEquals(false, jt400Configuration.isGuiAvailable()); + } + +} http://git-wip-us.apache.org/repos/asf/camel/blob/786c6606/components/camel-jt400/src/test/java/org/apache/camel/component/jt400/Jt400CustomPollStrategyTest.java ---------------------------------------------------------------------- diff --git a/components/camel-jt400/src/test/java/org/apache/camel/component/jt400/Jt400CustomPollStrategyTest.java b/components/camel-jt400/src/test/java/org/apache/camel/component/jt400/Jt400CustomPollStrategyTest.java index de1ff19..7aeef09 100644 --- a/components/camel-jt400/src/test/java/org/apache/camel/component/jt400/Jt400CustomPollStrategyTest.java +++ b/components/camel-jt400/src/test/java/org/apache/camel/component/jt400/Jt400CustomPollStrategyTest.java @@ -42,9 +42,9 @@ public class Jt400CustomPollStrategyTest extends Jt400TestSupport { @Test public void testCustomPollStrategy() throws Exception { - Jt400DataQueueEndpoint endpoint = resolveMandatoryEndpoint( + Jt400Endpoint endpoint = resolveMandatoryEndpoint( "jt400://user:" + PASSWORD + "@host/qsys.lib/library.lib/queue.dtaq?connectionPool=#mockPool&pollStrategy=#jt400PollStrategy", - Jt400DataQueueEndpoint.class); + Jt400Endpoint.class); assertNotNull(endpoint); PollingConsumer consumer = endpoint.createPollingConsumer(); http://git-wip-us.apache.org/repos/asf/camel/blob/786c6606/components/camel-jt400/src/test/java/org/apache/camel/component/jt400/Jt400DataQueueEndpointTest.java ---------------------------------------------------------------------- diff --git a/components/camel-jt400/src/test/java/org/apache/camel/component/jt400/Jt400DataQueueEndpointTest.java b/components/camel-jt400/src/test/java/org/apache/camel/component/jt400/Jt400DataQueueEndpointTest.java deleted file mode 100644 index 211f76b..0000000 --- a/components/camel-jt400/src/test/java/org/apache/camel/component/jt400/Jt400DataQueueEndpointTest.java +++ /dev/null @@ -1,53 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.apache.camel.component.jt400; - -import org.apache.camel.component.jt400.Jt400DataQueueEndpoint.Format; -import org.junit.Before; -import org.junit.Test; - -/** - * Test case for {@link Jt400DataQueueEndpoint} - */ -public class Jt400DataQueueEndpointTest extends Jt400TestSupport { - - private Jt400DataQueueEndpoint endpoint; - - @Override - @Before - public void setUp() throws Exception { - super.setUp(); - endpoint = (Jt400DataQueueEndpoint) resolveMandatoryEndpoint("jt400://user:password@host/qsys.lib/library.lib/queue.dtaq?ccsid=500&format=binary&guiAvailable=true&connectionPool=#mockPool"); - } - - /** - * Check that the AS/400 connection is correctly configured for the URL - */ - @Test - public void testSystemConfiguration() { - assertEquals("USER", endpoint.getSystem().getUserId()); - assertEquals("host", endpoint.getSystem().getSystemName()); - assertEquals(500, endpoint.getSystem().getCcsid()); - assertEquals(Format.binary, endpoint.getFormat()); - assertTrue(endpoint.getSystem().isGuiAvailable()); - } - - @Test - public void testToString() { - assertEquals("Endpoint[jt400://user:xxxxxx@host/qsys.lib/library.lib/queue.dtaq?ccsid=500&connectionPool=%23mockPool&format=binary&guiAvailable=true]", endpoint.toString()); - } -} http://git-wip-us.apache.org/repos/asf/camel/blob/786c6606/components/camel-jt400/src/test/java/org/apache/camel/component/jt400/Jt400DataQueueProducerTest.java ---------------------------------------------------------------------- diff --git a/components/camel-jt400/src/test/java/org/apache/camel/component/jt400/Jt400DataQueueProducerTest.java b/components/camel-jt400/src/test/java/org/apache/camel/component/jt400/Jt400DataQueueProducerTest.java index 9513746..5e6d25d 100644 --- a/components/camel-jt400/src/test/java/org/apache/camel/component/jt400/Jt400DataQueueProducerTest.java +++ b/components/camel-jt400/src/test/java/org/apache/camel/component/jt400/Jt400DataQueueProducerTest.java @@ -29,9 +29,9 @@ public class Jt400DataQueueProducerTest extends Jt400TestSupport { @Before public void setUp() throws Exception { super.setUp(); - Jt400DataQueueEndpoint endpoint = resolveMandatoryEndpoint( + Jt400Endpoint endpoint = resolveMandatoryEndpoint( "jt400://user:" + PASSWORD + "@host/qsys.lib/library.lib/queue.dtaq?connectionPool=#mockPool", - Jt400DataQueueEndpoint.class); + Jt400Endpoint.class); producer = new Jt400DataQueueProducer(endpoint); } http://git-wip-us.apache.org/repos/asf/camel/blob/786c6606/components/camel-jt400/src/test/java/org/apache/camel/component/jt400/Jt400EndpointConnectionTest.java ---------------------------------------------------------------------- diff --git a/components/camel-jt400/src/test/java/org/apache/camel/component/jt400/Jt400EndpointConnectionTest.java b/components/camel-jt400/src/test/java/org/apache/camel/component/jt400/Jt400EndpointConnectionTest.java deleted file mode 100644 index 35fe7c2..0000000 --- a/components/camel-jt400/src/test/java/org/apache/camel/component/jt400/Jt400EndpointConnectionTest.java +++ /dev/null @@ -1,66 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.apache.camel.component.jt400; - -import com.ibm.as400.access.AS400; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -public class Jt400EndpointConnectionTest extends Jt400TestSupport { - - private Jt400Endpoint jt400Endpoint; - private AS400 connection; - - @Before - public void setUp() throws Exception { - super.setUp(); - - jt400Endpoint = new Jt400Endpoint("jt400://USER:password@host/QSYS.LIB/LIBRARY.LIB/QUEUE.DTAQ", getConnectionPool()); - jt400Endpoint.setCcsid(37); - connection = jt400Endpoint.getConnection(); - } - - @After - public void tearDown() throws Exception { - if (connection != null) { - jt400Endpoint.releaseConnection(connection); - } - super.tearDown(); - } - - @Test - public void testSystemName() { - assertEquals("host", connection.getSystemName()); - } - - @Test - public void testUserId() { - assertEquals("USER", connection.getUserId()); - } - - @Test - public void testCssid() { - assertEquals(37, connection.getCcsid()); - } - - @Test - public void testGuiAvailable() { - assertFalse(connection.isGuiAvailable()); - } - -} http://git-wip-us.apache.org/repos/asf/camel/blob/786c6606/components/camel-jt400/src/test/java/org/apache/camel/component/jt400/Jt400EndpointTest.java ---------------------------------------------------------------------- diff --git a/components/camel-jt400/src/test/java/org/apache/camel/component/jt400/Jt400EndpointTest.java b/components/camel-jt400/src/test/java/org/apache/camel/component/jt400/Jt400EndpointTest.java index 868cc82..e71cd1f 100644 --- a/components/camel-jt400/src/test/java/org/apache/camel/component/jt400/Jt400EndpointTest.java +++ b/components/camel-jt400/src/test/java/org/apache/camel/component/jt400/Jt400EndpointTest.java @@ -16,53 +16,37 @@ */ package org.apache.camel.component.jt400; -import org.apache.camel.component.jt400.Jt400DataQueueEndpoint.Format; import org.junit.Before; import org.junit.Test; +/** + * Test case for {@link Jt400Endpoint} + */ public class Jt400EndpointTest extends Jt400TestSupport { - private Jt400Endpoint jt400Endpoint; + private Jt400Endpoint endpoint; + @Override @Before public void setUp() throws Exception { super.setUp(); - jt400Endpoint = new Jt400Endpoint("jt400://USER:password@host/QSYS.LIB/LIBRARY.LIB/QUEUE.DTAQ", getConnectionPool()); - } - - @Test - public void testSystemName() { - assertEquals("host", jt400Endpoint.getSystemName()); - } - - @Test - public void testUserID() { - assertEquals("USER", jt400Endpoint.getUserID()); - } - - @Test - public void testPassword() { - assertEquals("password", jt400Endpoint.getPassword()); - } - - @Test - public void testObjectPath() { - assertEquals("/QSYS.LIB/LIBRARY.LIB/QUEUE.DTAQ", jt400Endpoint.getObjectPath()); + endpoint = (Jt400Endpoint) resolveMandatoryEndpoint("jt400://user:password@host/qsys.lib/library.lib/queue.dtaq?ccsid=500&format=binary&guiAvailable=true&connectionPool=#mockPool"); } + /** + * Check that the AS/400 connection is correctly configured for the URL + */ @Test - public void testDefaultCcsid() { - assertEquals(-1, jt400Endpoint.getCssid()); + public void testSystemConfiguration() { + assertEquals("USER", endpoint.getSystem().getUserId()); + assertEquals("host", endpoint.getSystem().getSystemName()); + assertEquals(500, endpoint.getSystem().getCcsid()); + assertEquals(Jt400Configuration.Format.binary, endpoint.getFormat()); + assertTrue(endpoint.getSystem().isGuiAvailable()); } @Test - public void testDefaultFormat() { - assertEquals(Format.text, jt400Endpoint.getFormat()); + public void testToString() { + assertEquals("Endpoint[jt400://user:xxxxxx@host/qsys.lib/library.lib/queue.dtaq?ccsid=500&connectionPool=%23mockPool&format=binary&guiAvailable=true]", endpoint.toString()); } - - @Test - public void testDefaultGuiAvailable() { - assertEquals(false, jt400Endpoint.isGuiAvailable()); - } - } http://git-wip-us.apache.org/repos/asf/camel/blob/786c6606/components/camel-jt400/src/test/java/org/apache/camel/component/jt400/Jt400PgmEndpointTest.java ---------------------------------------------------------------------- diff --git a/components/camel-jt400/src/test/java/org/apache/camel/component/jt400/Jt400PgmEndpointTest.java b/components/camel-jt400/src/test/java/org/apache/camel/component/jt400/Jt400PgmEndpointTest.java index b8d6cdd..70470db 100644 --- a/components/camel-jt400/src/test/java/org/apache/camel/component/jt400/Jt400PgmEndpointTest.java +++ b/components/camel-jt400/src/test/java/org/apache/camel/component/jt400/Jt400PgmEndpointTest.java @@ -16,12 +16,11 @@ */ package org.apache.camel.component.jt400; -import org.apache.camel.component.jt400.Jt400DataQueueEndpoint.Format; import org.junit.Before; import org.junit.Test; /** - * Test case for {@link Jt400DataQueueEndpoint} + * Test case for {@link Jt400Endpoint} */ public class Jt400PgmEndpointTest extends Jt400TestSupport { @@ -30,13 +29,13 @@ public class Jt400PgmEndpointTest extends Jt400TestSupport { private static final String PASSWORD = "password"; private static final String PGM = "/qsys.lib/library.lib/prog.pgm"; - private Jt400PgmEndpoint endpoint; + private Jt400Endpoint endpoint; @Override @Before public void setUp() throws Exception { super.setUp(); - endpoint = (Jt400PgmEndpoint) resolveMandatoryEndpoint("jt400://" + USER + ":" + PASSWORD + endpoint = (Jt400Endpoint) resolveMandatoryEndpoint("jt400://" + USER + ":" + PASSWORD + "@" + HOST + PGM + "?connectionPool=#mockPool&guiAvailable=true&format=binary&outputFieldsIdx=1,2&fieldsLength=10,512,255"); } @@ -46,11 +45,11 @@ public class Jt400PgmEndpointTest extends Jt400TestSupport { */ @Test public void testSystemConfiguration() { - assertEquals(USER, endpoint.getiSeries().getUserId()); - assertEquals(HOST, endpoint.getiSeries().getSystemName()); - assertEquals(PGM, endpoint.getProgramToExecute()); - assertTrue(endpoint.getiSeries().isGuiAvailable()); - assertEquals(Format.binary, endpoint.getFormat()); + assertEquals(USER, endpoint.getUserID()); + assertEquals(HOST, endpoint.getSystemName()); + assertEquals(PGM, endpoint.getObjectPath()); + assertTrue(endpoint.isGuiAvailable()); + assertEquals(Jt400Configuration.Format.binary, endpoint.getFormat()); assertEquals(10, endpoint.getOutputFieldLength(0)); assertEquals(512, endpoint.getOutputFieldLength(1)); assertEquals(255, endpoint.getOutputFieldLength(2));