Skip to content

Commit

Permalink
jt400 mock coverage + native fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
JiriOndrusek committed Feb 27, 2024
1 parent 55759db commit b75ddc8
Show file tree
Hide file tree
Showing 20 changed files with 1,024 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,24 @@
import java.util.ArrayList;
import java.util.List;

import com.ibm.as400.access.ConvTable;
import com.ibm.as400.access.NLSImplNative;
import io.quarkus.deployment.annotations.BuildProducer;
import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.builditem.CombinedIndexBuildItem;
import io.quarkus.deployment.builditem.FeatureBuildItem;
import io.quarkus.deployment.builditem.IndexDependencyBuildItem;
import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem;
import io.quarkus.deployment.builditem.nativeimage.RuntimeInitializedClassBuildItem;
import org.jboss.jandex.DotName;
import org.jboss.jandex.IndexView;
import org.jboss.logging.Logger;

class Jt400Processor {

private static final Logger LOG = Logger.getLogger(Jt400Processor.class);
private static final String FEATURE = "camel-jt400";
private static final DotName CONV_TABLE_NAME = DotName.createSimple(ConvTable.class.getName());

@BuildStep
FeatureBuildItem feature() {
Expand All @@ -40,4 +49,30 @@ List<RuntimeInitializedClassBuildItem> runtimeInitializedClasses() {
items.add(new RuntimeInitializedClassBuildItem("com.ibm.as400.access.CredentialVault"));
return items;
}

@BuildStep
void reflectiveClasses(BuildProducer<ReflectiveClassBuildItem> reflectiveClassesProducer,
CombinedIndexBuildItem combinedIndex) {
IndexView index = combinedIndex.getIndex();

reflectiveClassesProducer.produce(ReflectiveClassBuildItem.builder(NLSImplNative.class).build());

index.getKnownClasses().stream()
.filter(c -> c.name().toString().matches("com.ibm.as400.access.*Remote"))
.map(c -> ReflectiveClassBuildItem.builder(c.name().toString()).build())
.forEach(reflectiveClassesProducer::produce);

combinedIndex.getIndex()
.getAllKnownSubclasses(CONV_TABLE_NAME)
.stream()
.map(c -> ReflectiveClassBuildItem.builder(c.name().toString()).build())
.forEach(reflectiveClassesProducer::produce);

}

@BuildStep
IndexDependencyBuildItem registerDependencyForIndex() {
return new IndexDependencyBuildItem("net.sf.jt400", "jt400", "java11");
}

}
24 changes: 24 additions & 0 deletions integration-tests/jt400/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@
<name>Camel Quarkus :: Integration Tests :: JT400</name>
<description>Integration tests for Camel Quarkus JT400 extension</description>

<properties>
<flat-class-path>true</flat-class-path>
</properties>

<dependencies>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
Expand All @@ -39,6 +43,10 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-jackson</artifactId>
</dependency>

<!-- test dependencies -->
<dependency>
Expand All @@ -63,6 +71,9 @@
</activation>
<properties>
<quarkus.package.type>native</quarkus.package.type>
<!-- Flat class has to be configured in build-time for native mode.
If property is not set, the native test will fail because build-time property is changed in runtime via testProfile -->
<quarkus.test.flat-class-path>${flat-class-path}</quarkus.test.flat-class-path>
</properties>
<build>
<plugins>
Expand Down Expand Up @@ -105,6 +116,19 @@
</dependency>
</dependencies>
</profile>
<profile>
<!-- Mock tests require flat classpath, which are enabled by default.
This profile disables flat classpath-->
<id>skip-mock-tests</id>
<activation>
<property>
<name>skip-mock-tests</name>
</property>
</activation>
<properties>
<flat-class-path>false</flat-class-path>
</properties>
</profile>
</profiles>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* 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 com.ibm.as400.access;

import java.io.IOException;

public class MockAS400 extends AS400 {

private final MockAS400ImplRemote as400ImplRemote;

public MockAS400(MockAS400ImplRemote as400ImplRemote) {
this.as400ImplRemote = as400ImplRemote;
}

@Override
public AS400Impl getImpl() {
return as400ImplRemote;
}

@Override
public int getCcsid() {
//ConvTable37 depends on this value
return 37;
}

@Override
public boolean isConnected(int service) {
//always connected
return true;
}

@Override
public void connectService(int service, int overridePort) throws AS400SecurityException, IOException {
//connection to real i server is ignored
setSignonInfo(-1, -1, "username");
}

@Override
synchronized void signon(boolean keepConnection) throws AS400SecurityException, IOException {
//do nothing
}

@Override
public int getVRM() throws AS400SecurityException, IOException {
return 1;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* 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 com.ibm.as400.access;

import java.io.IOException;

public class MockAS400ImplRemote extends AS400ImplRemote {

AS400Server getConnection(int service, boolean forceNewConnection,
boolean skipSignonServer) throws AS400SecurityException, IOException {
return new MockAS400Server(this);
}

@Override
public String getNLV() {
return "012345678901234567890123456789";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* 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 com.ibm.as400.access;

import java.io.IOException;

public class MockAS400Server extends AS400NoThreadServer {

MockAS400Server(AS400ImplRemote system) throws IOException {
super(system, 1, new MockSocketContainer(), "job/String/something");
}

@Override
public DataStream sendAndReceive(DataStream requestStream) throws IOException {
if (!MockedResponses.isEmpty()) {
return MockedResponses.removeFirst();
}

return null;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,30 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.camel.quarkus.component.jt400.it;
package com.ibm.as400.access;

import io.quarkus.test.junit.QuarkusTest;
import io.restassured.RestAssured;
import org.junit.jupiter.api.Test;
public class MockDataStream extends DataStream {
MockDataStream() {
super(30);
}

@Override
int getCorrelation() {
return 0;
}

@Override
int getLength() {
return 0;
}

@Override
void setCorrelation(int correlation) {

}

@QuarkusTest
public class Jt400Test {
@Override
void setLength(int len) {

@Test
public void loadComponentJt400() {
/* A simple autogenerated test */
RestAssured.get("/jt400/load/component/jt400")
.then()
.statusCode(200);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* 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 com.ibm.as400.access;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
import java.net.SocketException;

public class MockSocketContainer extends SocketContainer {

ByteArrayOutputStream bOutput = new ByteArrayOutputStream(50);

byte[] _data = new byte[50];

public MockSocketContainer() {

// https://github.com/IBM/JTOpen/blob/98e74fae6d212563a1558abce60ea5c73fcfc0c0/src/main/java/com/ibm/as400/access/ClientAccessDataStream.java#L70
_data[6] = (byte) 0xE0;

//sets length to 49
_data[1] = 0;
_data[2] = 0;
_data[3] = '1';

_data[4] = 0;
_data[5] = 0;
_data[7] = 0;
}

@Override
void setProperties(Socket socket, String serviceName, String systemName, int port, SSLOptions options) throws IOException {

}

@Override
void close() throws IOException {

}

@Override
InputStream getInputStream() throws IOException {
return new ByteArrayInputStream(_data);
}

@Override
OutputStream getOutputStream() throws IOException {
return bOutput;
}

@Override
void setSoTimeout(int timeout) throws SocketException {

}

@Override
int getSoTimeout() throws SocketException {
return 0;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* 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 com.ibm.as400.access;

import java.util.LinkedList;

public class MockedResponses {

private static LinkedList<DataStream> responses = new LinkedList<>();

public static void add(DataStream dataStream) {
responses.add(dataStream);
}

public static DataStream removeFirst() {
return responses.removeFirst();
}

public static boolean isEmpty() {
return responses.isEmpty();
}
}
Loading

0 comments on commit b75ddc8

Please sign in to comment.