删除编译错误
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
## JEE 7
|
||||
|
||||
This module contains articles about JEE 7.
|
||||
|
||||
### Relevant Articles:
|
||||
- [Scheduling in Jakarta EE](https://www.baeldung.com/scheduling-in-java-enterprise-edition)
|
||||
- [JSON Processing in Java EE 7](https://www.baeldung.com/jee7-json)
|
||||
- [Converters, Listeners and Validators in Java EE 7](https://www.baeldung.com/java-ee7-converter-listener-validator)
|
||||
- [Introduction to JAX-WS](https://www.baeldung.com/jax-ws)
|
||||
- [A Guide to Java EE Web-Related Annotations](https://www.baeldung.com/javaee-web-annotations)
|
||||
- [Introduction to Testing with Arquillian](https://www.baeldung.com/arquillian)
|
||||
- [Java EE 7 Batch Processing](https://www.baeldung.com/java-ee-7-batch-processing)
|
||||
- [The Difference Between CDI and EJB Singleton](https://www.baeldung.com/jee-cdi-vs-ejb-singleton)
|
||||
- [Invoking a SOAP Web Service in Java](https://www.baeldung.com/java-soap-web-service)
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,129 @@
|
||||
|
||||
package com.baeldung.soap.ws.client.generated;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAccessType;
|
||||
import javax.xml.bind.annotation.XmlAccessorType;
|
||||
import javax.xml.bind.annotation.XmlSchemaType;
|
||||
import javax.xml.bind.annotation.XmlType;
|
||||
|
||||
/**
|
||||
* <p>Java class for country complex type.
|
||||
*
|
||||
* <p>The following schema fragment specifies the expected content contained within this class.
|
||||
*
|
||||
* <pre>
|
||||
* <complexType name="country">
|
||||
* <complexContent>
|
||||
* <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
|
||||
* <sequence>
|
||||
* <element name="capital" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
|
||||
* <element name="currency" type="{http://server.ws.soap.baeldung.com/}currency" minOccurs="0"/>
|
||||
* <element name="name" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
|
||||
* <element name="population" type="{http://www.w3.org/2001/XMLSchema}int"/>
|
||||
* </sequence>
|
||||
* </restriction>
|
||||
* </complexContent>
|
||||
* </complexType>
|
||||
* </pre>
|
||||
*
|
||||
*
|
||||
*/
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
@XmlType(name = "country", propOrder = { "capital", "currency", "name", "population" })
|
||||
public class Country {
|
||||
|
||||
protected String capital;
|
||||
@XmlSchemaType(name = "string")
|
||||
protected Currency currency;
|
||||
protected String name;
|
||||
protected int population;
|
||||
|
||||
/**
|
||||
* Gets the value of the capital property.
|
||||
*
|
||||
* @return
|
||||
* possible object is
|
||||
* {@link String }
|
||||
*
|
||||
*/
|
||||
public String getCapital() {
|
||||
return capital;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value of the capital property.
|
||||
*
|
||||
* @param value
|
||||
* allowed object is
|
||||
* {@link String }
|
||||
*
|
||||
*/
|
||||
public void setCapital(String value) {
|
||||
this.capital = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the value of the currency property.
|
||||
*
|
||||
* @return
|
||||
* possible object is
|
||||
* {@link Currency }
|
||||
*
|
||||
*/
|
||||
public Currency getCurrency() {
|
||||
return currency;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value of the currency property.
|
||||
*
|
||||
* @param value
|
||||
* allowed object is
|
||||
* {@link Currency }
|
||||
*
|
||||
*/
|
||||
public void setCurrency(Currency value) {
|
||||
this.currency = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the value of the name property.
|
||||
*
|
||||
* @return
|
||||
* possible object is
|
||||
* {@link String }
|
||||
*
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value of the name property.
|
||||
*
|
||||
* @param value
|
||||
* allowed object is
|
||||
* {@link String }
|
||||
*
|
||||
*/
|
||||
public void setName(String value) {
|
||||
this.name = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the value of the population property.
|
||||
*
|
||||
*/
|
||||
public int getPopulation() {
|
||||
return population;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value of the population property.
|
||||
*
|
||||
*/
|
||||
public void setPopulation(int value) {
|
||||
this.population = value;
|
||||
}
|
||||
|
||||
}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
|
||||
package com.baeldung.soap.ws.client.generated;
|
||||
|
||||
import javax.jws.WebMethod;
|
||||
import javax.jws.WebParam;
|
||||
import javax.jws.WebResult;
|
||||
import javax.jws.WebService;
|
||||
import javax.jws.soap.SOAPBinding;
|
||||
import javax.xml.bind.annotation.XmlSeeAlso;
|
||||
import javax.xml.ws.Action;
|
||||
|
||||
/**
|
||||
* This class was generated by the JAX-WS RI.
|
||||
* JAX-WS RI 2.3.2
|
||||
* Generated source version: 2.2
|
||||
*
|
||||
*/
|
||||
@WebService(name = "CountryService", targetNamespace = "http://server.ws.soap.baeldung.com/")
|
||||
@SOAPBinding(style = SOAPBinding.Style.RPC)
|
||||
@XmlSeeAlso({ ObjectFactory.class })
|
||||
public interface CountryService {
|
||||
|
||||
/**
|
||||
*
|
||||
* @param arg0
|
||||
* @return
|
||||
* returns com.baeldung.soap.ws.client.generated.Country
|
||||
*/
|
||||
@WebMethod
|
||||
@WebResult(partName = "return")
|
||||
@Action(input = "http://server.ws.soap.baeldung.com/CountryService/findByNameRequest", output = "http://server.ws.soap.baeldung.com/CountryService/findByNameResponse")
|
||||
public Country findByName(@WebParam(name = "arg0", partName = "arg0") String arg0);
|
||||
|
||||
}
|
||||
+91
@@ -0,0 +1,91 @@
|
||||
|
||||
package com.baeldung.soap.ws.client.generated;
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import javax.xml.namespace.QName;
|
||||
import javax.xml.ws.Service;
|
||||
import javax.xml.ws.WebEndpoint;
|
||||
import javax.xml.ws.WebServiceClient;
|
||||
import javax.xml.ws.WebServiceException;
|
||||
import javax.xml.ws.WebServiceFeature;
|
||||
|
||||
/**
|
||||
* This class was generated by the JAX-WS RI.
|
||||
* JAX-WS RI 2.2.9-b130926.1035
|
||||
* Generated source version: 2.2
|
||||
*
|
||||
*/
|
||||
@WebServiceClient(name = "CountryServiceImplService", targetNamespace = "http://server.ws.soap.baeldung.com/", wsdlLocation = "http://localhost:8888/ws/country?wsdl")
|
||||
public class CountryServiceImplService extends Service {
|
||||
|
||||
private final static URL COUNTRYSERVICEIMPLSERVICE_WSDL_LOCATION;
|
||||
private final static WebServiceException COUNTRYSERVICEIMPLSERVICE_EXCEPTION;
|
||||
private final static QName COUNTRYSERVICEIMPLSERVICE_QNAME = new QName("http://server.ws.soap.baeldung.com/", "CountryServiceImplService");
|
||||
|
||||
static {
|
||||
URL url = null;
|
||||
WebServiceException e = null;
|
||||
try {
|
||||
url = new URL("http://localhost:8888/ws/country?wsdl");
|
||||
} catch (MalformedURLException ex) {
|
||||
e = new WebServiceException(ex);
|
||||
}
|
||||
COUNTRYSERVICEIMPLSERVICE_WSDL_LOCATION = url;
|
||||
COUNTRYSERVICEIMPLSERVICE_EXCEPTION = e;
|
||||
}
|
||||
|
||||
public CountryServiceImplService() {
|
||||
super(__getWsdlLocation(), COUNTRYSERVICEIMPLSERVICE_QNAME);
|
||||
}
|
||||
|
||||
public CountryServiceImplService(WebServiceFeature... features) {
|
||||
super(__getWsdlLocation(), COUNTRYSERVICEIMPLSERVICE_QNAME, features);
|
||||
}
|
||||
|
||||
public CountryServiceImplService(URL wsdlLocation) {
|
||||
super(wsdlLocation, COUNTRYSERVICEIMPLSERVICE_QNAME);
|
||||
}
|
||||
|
||||
public CountryServiceImplService(URL wsdlLocation, WebServiceFeature... features) {
|
||||
super(wsdlLocation, COUNTRYSERVICEIMPLSERVICE_QNAME, features);
|
||||
}
|
||||
|
||||
public CountryServiceImplService(URL wsdlLocation, QName serviceName) {
|
||||
super(wsdlLocation, serviceName);
|
||||
}
|
||||
|
||||
public CountryServiceImplService(URL wsdlLocation, QName serviceName, WebServiceFeature... features) {
|
||||
super(wsdlLocation, serviceName, features);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
* returns CountryService
|
||||
*/
|
||||
@WebEndpoint(name = "CountryServiceImplPort")
|
||||
public CountryService getCountryServiceImplPort() {
|
||||
return super.getPort(new QName("http://server.ws.soap.baeldung.com/", "CountryServiceImplPort"), CountryService.class);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param features
|
||||
* A list of {@link javax.xml.ws.WebServiceFeature} to configure on the proxy. Supported features not in the <code>features</code> parameter will have their default values.
|
||||
* @return
|
||||
* returns CountryService
|
||||
*/
|
||||
@WebEndpoint(name = "CountryServiceImplPort")
|
||||
public CountryService getCountryServiceImplPort(WebServiceFeature... features) {
|
||||
return super.getPort(new QName("http://server.ws.soap.baeldung.com/", "CountryServiceImplPort"), CountryService.class, features);
|
||||
}
|
||||
|
||||
private static URL __getWsdlLocation() {
|
||||
if (COUNTRYSERVICEIMPLSERVICE_EXCEPTION != null) {
|
||||
throw COUNTRYSERVICEIMPLSERVICE_EXCEPTION;
|
||||
}
|
||||
return COUNTRYSERVICEIMPLSERVICE_WSDL_LOCATION;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
|
||||
package com.baeldung.soap.ws.client.generated;
|
||||
|
||||
import javax.xml.bind.annotation.XmlEnum;
|
||||
import javax.xml.bind.annotation.XmlType;
|
||||
|
||||
/**
|
||||
* <p>Java class for currency.
|
||||
*
|
||||
* <p>The following schema fragment specifies the expected content contained within this class.
|
||||
* <p>
|
||||
* <pre>
|
||||
* <simpleType name="currency">
|
||||
* <restriction base="{http://www.w3.org/2001/XMLSchema}string">
|
||||
* <enumeration value="EUR"/>
|
||||
* <enumeration value="INR"/>
|
||||
* <enumeration value="USD"/>
|
||||
* </restriction>
|
||||
* </simpleType>
|
||||
* </pre>
|
||||
*
|
||||
*/
|
||||
@XmlType(name = "currency")
|
||||
@XmlEnum
|
||||
public enum Currency {
|
||||
|
||||
EUR, INR, USD;
|
||||
|
||||
public String value() {
|
||||
return name();
|
||||
}
|
||||
|
||||
public static Currency fromValue(String v) {
|
||||
return valueOf(v);
|
||||
}
|
||||
|
||||
}
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
|
||||
package com.baeldung.soap.ws.client.generated;
|
||||
|
||||
import javax.xml.bind.annotation.XmlRegistry;
|
||||
|
||||
/**
|
||||
* This object contains factory methods for each
|
||||
* Java content interface and Java element interface
|
||||
* generated in the com.baeldung.soap.ws.client.generated package.
|
||||
* <p>An ObjectFactory allows you to programatically
|
||||
* construct new instances of the Java representation
|
||||
* for XML content. The Java representation of XML
|
||||
* content can consist of schema derived interfaces
|
||||
* and classes representing the binding of schema
|
||||
* type definitions, element declarations and model
|
||||
* groups. Factory methods for each of these are
|
||||
* provided in this class.
|
||||
*
|
||||
*/
|
||||
@XmlRegistry
|
||||
public class ObjectFactory {
|
||||
|
||||
/**
|
||||
* Create a new ObjectFactory that can be used to create new instances of schema derived classes for package: com.baeldung.soap.ws.client.generated
|
||||
*
|
||||
*/
|
||||
public ObjectFactory() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an instance of {@link Country }
|
||||
*
|
||||
*/
|
||||
public Country createCountry() {
|
||||
return new Country();
|
||||
}
|
||||
|
||||
}
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
@javax.xml.bind.annotation.XmlSchema(namespace = "http://server.ws.soap.baeldung.com/", elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED)
|
||||
package com.baeldung.soap.ws.client.generated;
|
||||
@@ -0,0 +1,41 @@
|
||||
package com.baeldung.soap.ws.server;
|
||||
|
||||
public class Country {
|
||||
protected String name;
|
||||
protected int population;
|
||||
protected String capital;
|
||||
protected Currency currency;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public int getPopulation() {
|
||||
return population;
|
||||
}
|
||||
|
||||
public void setPopulation(int population) {
|
||||
this.population = population;
|
||||
}
|
||||
|
||||
public String getCapital() {
|
||||
return capital;
|
||||
}
|
||||
|
||||
public void setCapital(String capital) {
|
||||
this.capital = capital;
|
||||
}
|
||||
|
||||
public Currency getCurrency() {
|
||||
return currency;
|
||||
}
|
||||
|
||||
public void setCurrency(Currency currency) {
|
||||
this.currency = currency;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package com.baeldung.soap.ws.server;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class CountryRepository {
|
||||
|
||||
private static final Map<String, Country> countries = new HashMap<>();
|
||||
|
||||
{
|
||||
initData();
|
||||
}
|
||||
|
||||
private final static void initData() {
|
||||
Country usa = new Country();
|
||||
usa.setName("USA");
|
||||
usa.setCapital("Washington D.C.");
|
||||
usa.setCurrency(Currency.USD);
|
||||
usa.setPopulation(323947000);
|
||||
|
||||
countries.put(usa.getName(), usa);
|
||||
|
||||
Country india = new Country();
|
||||
india.setName("India");
|
||||
india.setCapital("New Delhi");
|
||||
india.setCurrency(Currency.INR);
|
||||
india.setPopulation(1295210000);
|
||||
|
||||
countries.put(india.getName(), india);
|
||||
|
||||
Country france = new Country();
|
||||
france.setName("France");
|
||||
france.setCapital("Paris");
|
||||
france.setCurrency(Currency.EUR);
|
||||
france.setPopulation(66710000);
|
||||
|
||||
countries.put(france.getName(), france);
|
||||
}
|
||||
|
||||
public Country findCountry(String name) {
|
||||
return countries.get(name);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.baeldung.soap.ws.server;
|
||||
|
||||
import javax.jws.WebMethod;
|
||||
import javax.jws.WebService;
|
||||
import javax.jws.soap.SOAPBinding;
|
||||
import javax.jws.soap.SOAPBinding.Style;
|
||||
|
||||
@WebService
|
||||
@SOAPBinding(style=Style.RPC)
|
||||
public interface CountryService {
|
||||
|
||||
@WebMethod
|
||||
Country findByName(String name);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.baeldung.soap.ws.server;
|
||||
|
||||
import javax.jws.WebService;
|
||||
|
||||
@WebService(endpointInterface = "com.baeldung.soap.ws.server.CountryService")
|
||||
public class CountryServiceImpl implements CountryService {
|
||||
|
||||
private CountryRepository countryRepository = new CountryRepository();
|
||||
|
||||
@Override
|
||||
public Country findByName(String name) {
|
||||
return countryRepository.findCountry(name);
|
||||
}
|
||||
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
package com.baeldung.soap.ws.server;
|
||||
|
||||
import javax.xml.ws.Endpoint;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
||||
public class CountryServicePublisher {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(CountryServicePublisher.class);
|
||||
|
||||
public static void main(String[] args) {
|
||||
Endpoint endpoint = Endpoint.create(new CountryServiceImpl());
|
||||
endpoint.publish("http://localhost:8888/ws/country");
|
||||
|
||||
logger.info("Country web service ready to consume requests!");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.baeldung.soap.ws.server;
|
||||
|
||||
public enum Currency {
|
||||
|
||||
EUR, INR, USD;
|
||||
|
||||
public String value() {
|
||||
return name();
|
||||
}
|
||||
|
||||
public static Currency fromValue(String v) {
|
||||
return valueOf(v);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?><!-- Published by JAX-WS RI (http://jax-ws.java.net). RI's version is JAX-WS RI 2.2.9-b130926.1035 svn-revision#5f6196f2b90e9460065a4c2f4e30e065b245e51e. -->
|
||||
<xs:schema xmlns:tns="http://server.ws.soap.baeldung.com/" xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" version="1.0"
|
||||
targetNamespace="http://server.ws.soap.baeldung.com/">
|
||||
|
||||
<xs:complexType name="country">
|
||||
<xs:sequence>
|
||||
<xs:element name="capital" type="xs:string" minOccurs="0"></xs:element>
|
||||
<xs:element name="currency" type="tns:currency" minOccurs="0"></xs:element>
|
||||
<xs:element name="name" type="xs:string" minOccurs="0"></xs:element>
|
||||
<xs:element name="population" type="xs:int"></xs:element>
|
||||
</xs:sequence>
|
||||
</xs:complexType>
|
||||
|
||||
<xs:simpleType name="currency">
|
||||
<xs:restriction base="xs:string">
|
||||
<xs:enumeration value="EUR"></xs:enumeration>
|
||||
<xs:enumeration value="INR"></xs:enumeration>
|
||||
<xs:enumeration value="USD"></xs:enumeration>
|
||||
</xs:restriction>
|
||||
</xs:simpleType>
|
||||
</xs:schema>
|
||||
@@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<configuration>
|
||||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder>
|
||||
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
|
||||
</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<logger name="org.jboss.weld" level="WARN" />
|
||||
|
||||
<root level="INFO">
|
||||
<appender-ref ref="STDOUT" />
|
||||
</root>
|
||||
</configuration>
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
package com.baeldung.batch.understanding;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import javax.batch.operations.JobOperator;
|
||||
import javax.batch.runtime.BatchRuntime;
|
||||
import javax.batch.runtime.BatchStatus;
|
||||
import javax.batch.runtime.JobExecution;
|
||||
import javax.batch.runtime.StepExecution;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class CustomCheckPointIntegrationTest {
|
||||
@Test
|
||||
public void givenChunk_whenCustomCheckPoint_thenCommitCountIsThree() throws Exception {
|
||||
JobOperator jobOperator = BatchRuntime.getJobOperator();
|
||||
Long executionId = jobOperator.start("customCheckPoint", new Properties());
|
||||
JobExecution jobExecution = jobOperator.getJobExecution(executionId);
|
||||
jobExecution = BatchTestHelper.keepTestAlive(jobExecution);
|
||||
for (StepExecution stepExecution : jobOperator.getStepExecutions(executionId)) {
|
||||
if (stepExecution.getStepName()
|
||||
.equals("firstChunkStep")) {
|
||||
jobOperator.getStepExecutions(executionId)
|
||||
.stream()
|
||||
.map(BatchTestHelper::getCommitCount)
|
||||
.forEach(count -> assertEquals(3L, count.longValue()));
|
||||
}
|
||||
}
|
||||
assertEquals(jobExecution.getBatchStatus(), BatchStatus.COMPLETED);
|
||||
}
|
||||
}
|
||||
+76
@@ -0,0 +1,76 @@
|
||||
package com.baeldung.batch.understanding;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
import javax.batch.operations.JobOperator;
|
||||
import javax.batch.runtime.BatchRuntime;
|
||||
import javax.batch.runtime.BatchStatus;
|
||||
import javax.batch.runtime.JobExecution;
|
||||
import javax.batch.runtime.StepExecution;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class JobSequenceIntegrationTest {
|
||||
@Test
|
||||
public void givenTwoSteps_thenBatch_CompleteWithSuccess() throws Exception {
|
||||
JobOperator jobOperator = BatchRuntime.getJobOperator();
|
||||
Long executionId = jobOperator.start("simpleJobSequence", new Properties());
|
||||
JobExecution jobExecution = jobOperator.getJobExecution(executionId);
|
||||
jobExecution = BatchTestHelper.keepTestAlive(jobExecution);
|
||||
assertEquals(2 , jobOperator.getStepExecutions(executionId).size());
|
||||
assertEquals(jobExecution.getBatchStatus(), BatchStatus.COMPLETED);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenFlow_thenBatch_CompleteWithSuccess() throws Exception {
|
||||
JobOperator jobOperator = BatchRuntime.getJobOperator();
|
||||
Long executionId = jobOperator.start("flowJobSequence", new Properties());
|
||||
JobExecution jobExecution = jobOperator.getJobExecution(executionId);
|
||||
jobExecution = BatchTestHelper.keepTestAlive(jobExecution);
|
||||
assertEquals(3 , jobOperator.getStepExecutions(executionId).size());
|
||||
assertEquals(jobExecution.getBatchStatus(), BatchStatus.COMPLETED);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenDecider_thenBatch_CompleteWithSuccess() throws Exception {
|
||||
JobOperator jobOperator = BatchRuntime.getJobOperator();
|
||||
Long executionId = jobOperator.start("decideJobSequence", new Properties());
|
||||
JobExecution jobExecution = jobOperator.getJobExecution(executionId);
|
||||
jobExecution = BatchTestHelper.keepTestAlive(jobExecution);
|
||||
List<StepExecution> stepExecutions = jobOperator.getStepExecutions(executionId);
|
||||
List<String> executedSteps = new ArrayList<>();
|
||||
for (StepExecution stepExecution : stepExecutions) {
|
||||
executedSteps.add(stepExecution.getStepName());
|
||||
}
|
||||
assertEquals(2, jobOperator.getStepExecutions(executionId).size());
|
||||
assertArrayEquals(new String[] { "firstBatchStepStep1", "firstBatchStepStep3" }, executedSteps.toArray());
|
||||
assertEquals(jobExecution.getBatchStatus(), BatchStatus.COMPLETED);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenSplit_thenBatch_CompletesWithSuccess() throws Exception {
|
||||
JobOperator jobOperator = BatchRuntime.getJobOperator();
|
||||
Long executionId = jobOperator.start("splitJobSequence", new Properties());
|
||||
JobExecution jobExecution = jobOperator.getJobExecution(executionId);
|
||||
jobExecution = BatchTestHelper.keepTestAlive(jobExecution);
|
||||
List<StepExecution> stepExecutions = jobOperator.getStepExecutions(executionId);
|
||||
List<String> executedSteps = new ArrayList<>();
|
||||
for (StepExecution stepExecution : stepExecutions) {
|
||||
executedSteps.add(stepExecution.getStepName());
|
||||
}
|
||||
assertEquals(3, stepExecutions.size());
|
||||
assertTrue(executedSteps.contains("splitJobSequenceStep1"));
|
||||
assertTrue(executedSteps.contains("splitJobSequenceStep2"));
|
||||
assertTrue(executedSteps.contains("splitJobSequenceStep3"));
|
||||
assertTrue(executedSteps.get(0).equals("splitJobSequenceStep1") || executedSteps.get(0).equals("splitJobSequenceStep2"));
|
||||
assertTrue(executedSteps.get(1).equals("splitJobSequenceStep1") || executedSteps.get(1).equals("splitJobSequenceStep2"));
|
||||
assertTrue(executedSteps.get(2).equals("splitJobSequenceStep3"));
|
||||
assertEquals(jobExecution.getBatchStatus(), BatchStatus.COMPLETED);
|
||||
}
|
||||
}
|
||||
+64
@@ -0,0 +1,64 @@
|
||||
package com.baeldung.batch.understanding;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import javax.batch.operations.JobOperator;
|
||||
import javax.batch.runtime.BatchRuntime;
|
||||
import javax.batch.runtime.BatchStatus;
|
||||
import javax.batch.runtime.JobExecution;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class SimpleBatchLetIntegrationTest {
|
||||
@Test
|
||||
public void givenBatchLet_thenBatch_CompleteWithSuccess() throws Exception {
|
||||
JobOperator jobOperator = BatchRuntime.getJobOperator();
|
||||
Long executionId = jobOperator.start("simpleBatchLet", new Properties());
|
||||
JobExecution jobExecution = jobOperator.getJobExecution(executionId);
|
||||
jobExecution = BatchTestHelper.keepTestAlive(jobExecution);
|
||||
assertEquals(jobExecution.getBatchStatus(), BatchStatus.COMPLETED);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenBatchLetProperty_thenBatch_CompleteWithSuccess() throws Exception {
|
||||
JobOperator jobOperator = BatchRuntime.getJobOperator();
|
||||
Long executionId = jobOperator.start("injectionSimpleBatchLet", new Properties());
|
||||
JobExecution jobExecution = jobOperator.getJobExecution(executionId);
|
||||
jobExecution = BatchTestHelper.keepTestAlive(jobExecution);
|
||||
assertEquals(jobExecution.getBatchStatus(), BatchStatus.COMPLETED);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenBatchLetPartition_thenBatch_CompleteWithSuccess() throws Exception {
|
||||
JobOperator jobOperator = BatchRuntime.getJobOperator();
|
||||
Long executionId = jobOperator.start("partitionSimpleBatchLet", new Properties());
|
||||
JobExecution jobExecution = jobOperator.getJobExecution(executionId);
|
||||
jobExecution = BatchTestHelper.keepTestAlive(jobExecution);
|
||||
assertEquals(jobExecution.getBatchStatus(), BatchStatus.COMPLETED);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenBatchLetStarted_whenStopped_thenBatchStopped() throws Exception {
|
||||
JobOperator jobOperator = BatchRuntime.getJobOperator();
|
||||
Long executionId = jobOperator.start("simpleBatchLet", new Properties());
|
||||
JobExecution jobExecution = jobOperator.getJobExecution(executionId);
|
||||
jobOperator.stop(executionId);
|
||||
jobExecution = BatchTestHelper.keepTestStopped(jobExecution);
|
||||
assertEquals(jobExecution.getBatchStatus(), BatchStatus.STOPPED);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenBatchLetStopped_whenRestarted_thenBatchCompletesSuccess() throws Exception {
|
||||
JobOperator jobOperator = BatchRuntime.getJobOperator();
|
||||
Long executionId = jobOperator.start("simpleBatchLet", new Properties());
|
||||
JobExecution jobExecution = jobOperator.getJobExecution(executionId);
|
||||
jobOperator.stop(executionId);
|
||||
jobExecution = BatchTestHelper.keepTestStopped(jobExecution);
|
||||
assertEquals(jobExecution.getBatchStatus(), BatchStatus.STOPPED);
|
||||
executionId = jobOperator.restart(jobExecution.getExecutionId(), new Properties());
|
||||
jobExecution = BatchTestHelper.keepTestAlive(jobOperator.getJobExecution(executionId));
|
||||
assertEquals(jobExecution.getBatchStatus(), BatchStatus.COMPLETED);
|
||||
}
|
||||
}
|
||||
+68
@@ -0,0 +1,68 @@
|
||||
package com.baeldung.batch.understanding;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import javax.batch.operations.JobOperator;
|
||||
import javax.batch.runtime.BatchRuntime;
|
||||
import javax.batch.runtime.BatchStatus;
|
||||
import javax.batch.runtime.JobExecution;
|
||||
import javax.batch.runtime.Metric;
|
||||
import javax.batch.runtime.StepExecution;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class SimpleChunkIntegrationTest {
|
||||
@Test
|
||||
public void givenChunk_thenBatch_CompletesWithSucess() throws Exception {
|
||||
JobOperator jobOperator = BatchRuntime.getJobOperator();
|
||||
Long executionId = jobOperator.start("simpleChunk", new Properties());
|
||||
JobExecution jobExecution = jobOperator.getJobExecution(executionId);
|
||||
jobExecution = BatchTestHelper.keepTestAlive(jobExecution);
|
||||
List<StepExecution> stepExecutions = jobOperator.getStepExecutions(executionId);
|
||||
for (StepExecution stepExecution : stepExecutions) {
|
||||
if (stepExecution.getStepName()
|
||||
.equals("firstChunkStep")) {
|
||||
Map<Metric.MetricType, Long> metricsMap = BatchTestHelper.getMetricsMap(stepExecution.getMetrics());
|
||||
assertEquals(10L, metricsMap.get(Metric.MetricType.READ_COUNT)
|
||||
.longValue());
|
||||
assertEquals(10L / 2L, metricsMap.get(Metric.MetricType.WRITE_COUNT)
|
||||
.longValue());
|
||||
assertEquals(10L / 3 + (10L % 3 > 0 ? 1 : 0), metricsMap.get(Metric.MetricType.COMMIT_COUNT)
|
||||
.longValue());
|
||||
}
|
||||
}
|
||||
assertEquals(jobExecution.getBatchStatus(), BatchStatus.COMPLETED);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenChunk__thenBatch_fetchInformation() throws Exception {
|
||||
JobOperator jobOperator = BatchRuntime.getJobOperator();
|
||||
Long executionId = jobOperator.start("simpleChunk", new Properties());
|
||||
JobExecution jobExecution = jobOperator.getJobExecution(executionId);
|
||||
jobExecution = BatchTestHelper.keepTestAlive(jobExecution);
|
||||
// job name contains simpleBatchLet which is the name of the file
|
||||
assertTrue(jobOperator.getJobNames().contains("simpleChunk"));
|
||||
// job parameters are empty
|
||||
assertTrue(jobOperator.getParameters(executionId).isEmpty());
|
||||
// step execution information
|
||||
List<StepExecution> stepExecutions = jobOperator.getStepExecutions(executionId);
|
||||
assertEquals("firstChunkStep", stepExecutions.get(0).getStepName());
|
||||
// finding out batch status
|
||||
assertEquals(BatchStatus.COMPLETED, stepExecutions.get(0).getBatchStatus());
|
||||
Map<Metric.MetricType, Long> metricTest = BatchTestHelper.getMetricsMap(stepExecutions.get(0).getMetrics());
|
||||
assertEquals(10L, metricTest.get(Metric.MetricType.READ_COUNT).longValue());
|
||||
assertEquals(5L, metricTest.get(Metric.MetricType.FILTER_COUNT).longValue());
|
||||
assertEquals(4L, metricTest.get(Metric.MetricType.COMMIT_COUNT).longValue());
|
||||
assertEquals(5L, metricTest.get(Metric.MetricType.WRITE_COUNT).longValue());
|
||||
assertEquals(0L, metricTest.get(Metric.MetricType.READ_SKIP_COUNT).longValue());
|
||||
assertEquals(0L, metricTest.get(Metric.MetricType.WRITE_SKIP_COUNT).longValue());
|
||||
assertEquals(0L, metricTest.get(Metric.MetricType.PROCESS_SKIP_COUNT).longValue());
|
||||
assertEquals(0L, metricTest.get(Metric.MetricType.ROLLBACK_COUNT).longValue());
|
||||
assertEquals(jobExecution.getBatchStatus(), BatchStatus.COMPLETED);
|
||||
}
|
||||
}
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
package com.baeldung.batch.understanding;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
import javax.batch.operations.JobOperator;
|
||||
import javax.batch.runtime.BatchRuntime;
|
||||
import javax.batch.runtime.BatchStatus;
|
||||
import javax.batch.runtime.JobExecution;
|
||||
import javax.batch.runtime.StepExecution;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class SimpleErrorChunkIntegrationTest {
|
||||
|
||||
@Test
|
||||
public void givenChunkError_thenBatch_CompletesWithFailed() throws Exception {
|
||||
JobOperator jobOperator = BatchRuntime.getJobOperator();
|
||||
Long executionId = jobOperator.start("simpleErrorChunk", new Properties());
|
||||
JobExecution jobExecution = jobOperator.getJobExecution(executionId);
|
||||
jobExecution = BatchTestHelper.keepTestFailed(jobExecution);
|
||||
assertEquals(jobExecution.getBatchStatus(), BatchStatus.FAILED);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenChunkError_thenErrorSkipped_CompletesWithSuccess() throws Exception {
|
||||
JobOperator jobOperator = BatchRuntime.getJobOperator();
|
||||
Long executionId = jobOperator.start("simpleErrorSkipChunk", new Properties());
|
||||
JobExecution jobExecution = jobOperator.getJobExecution(executionId);
|
||||
jobExecution = BatchTestHelper.keepTestAlive(jobExecution);
|
||||
List<StepExecution> stepExecutions = jobOperator.getStepExecutions(executionId);
|
||||
for (StepExecution stepExecution : stepExecutions) {
|
||||
if (stepExecution.getStepName()
|
||||
.equals("errorStep")) {
|
||||
jobOperator.getStepExecutions(executionId)
|
||||
.stream()
|
||||
.map(BatchTestHelper::getProcessSkipCount)
|
||||
.forEach(skipCount -> assertEquals(1L, skipCount.longValue()));
|
||||
}
|
||||
}
|
||||
assertEquals(jobExecution.getBatchStatus(), BatchStatus.COMPLETED);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
package com.baeldung.singleton;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.ejb.EJB;
|
||||
import javax.enterprise.context.spi.CreationalContext;
|
||||
import javax.enterprise.inject.spi.Bean;
|
||||
import javax.enterprise.inject.spi.BeanManager;
|
||||
import javax.enterprise.inject.spi.CDI;
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.jboss.arquillian.container.test.api.Deployment;
|
||||
import org.jboss.arquillian.junit.Arquillian;
|
||||
import org.jboss.shrinkwrap.api.ShrinkWrap;
|
||||
import org.jboss.shrinkwrap.api.asset.EmptyAsset;
|
||||
import org.jboss.shrinkwrap.api.spec.JavaArchive;
|
||||
import org.junit.Before;
|
||||
import org.junit.FixMethodOrder;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.MethodSorters;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@RunWith(Arquillian.class)
|
||||
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
||||
public class CarServiceLiveTest {
|
||||
|
||||
public static final Logger LOG = LoggerFactory.getLogger(CarServiceLiveTest.class);
|
||||
|
||||
@Deployment
|
||||
public static JavaArchive createDeployment() {
|
||||
return ShrinkWrap.create(JavaArchive.class)
|
||||
.addClasses(CarServiceBean.class, CarServiceSingleton.class, CarServiceEjbSingleton.class, Car.class)
|
||||
.addAsResource("META-INF/persistence.xml")
|
||||
.addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
|
||||
}
|
||||
|
||||
@Inject
|
||||
private CarServiceBean carServiceBean;
|
||||
|
||||
@Inject
|
||||
private CarServiceSingleton carServiceSingleton;
|
||||
|
||||
@EJB
|
||||
private CarServiceEjbSingleton carServiceEjbSingleton;
|
||||
|
||||
@Test
|
||||
public void givenASingleton_whenGetBeanIsCalledTwice_thenTheSameInstanceIsReturned() {
|
||||
CarServiceSingleton one = getBean(CarServiceSingleton.class);
|
||||
CarServiceSingleton two = getBean(CarServiceSingleton.class);
|
||||
assertTrue(one == two);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenAPojo_whenGetBeanIsCalledTwice_thenDifferentInstancesAreReturned() {
|
||||
CarServiceBean one = getBean(CarServiceBean.class);
|
||||
CarServiceBean two = getBean(CarServiceBean.class);
|
||||
assertTrue(one != two);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private <T> T getBean(Class<T> beanClass) {
|
||||
BeanManager bm = CDI.current().getBeanManager();
|
||||
Bean<T> bean = (Bean<T>) bm.getBeans(beanClass).iterator().next();
|
||||
CreationalContext<T> ctx = bm.createCreationalContext(bean);
|
||||
return (T) bm.getReference(bean, beanClass, ctx);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenCDI_whenConcurrentAccess_thenLockingIsNotProvided() {
|
||||
for (int i = 0; i < 10; i++) {
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
String model = Double.toString(Math.round(Math.random() * 100));
|
||||
Car car = new Car("Speedster", model);
|
||||
int serviceQueue = carServiceSingleton.service(car);
|
||||
assertTrue(serviceQueue < 10);
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenEJB_whenConcurrentAccess_thenLockingIsProvided() {
|
||||
for (int i = 0; i < 10; i++) {
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
String model = Double.toString(Math.round(Math.random() * 100));
|
||||
Car car = new Car("Speedster", model);
|
||||
int serviceQueue = carServiceEjbSingleton.service(car);
|
||||
assertEquals(0, serviceQueue);
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
package com.baeldung.soap.ws.client;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.baeldung.soap.ws.client.generated.CountryService;
|
||||
import com.baeldung.soap.ws.client.generated.CountryServiceImplService;
|
||||
import com.baeldung.soap.ws.client.generated.Currency;
|
||||
|
||||
//Ensure that com.baeldung.soap.ws.server.CountryServicePublisher is running before executing this test
|
||||
public class CountryClientLiveTest {
|
||||
|
||||
private static CountryService countryService;
|
||||
|
||||
@BeforeClass
|
||||
public static void setup() {
|
||||
CountryServiceImplService service = new CountryServiceImplService();
|
||||
countryService = service.getCountryServiceImplPort();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenCountryService_whenCountryIndia_thenCapitalIsNewDelhi() {
|
||||
assertEquals("New Delhi", countryService.findByName("India").getCapital());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenCountryService_whenCountryFrance_thenPopulationCorrect() {
|
||||
assertEquals(66710000, countryService.findByName("France").getPopulation());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenCountryService_whenCountryUSA_thenCurrencyUSD() {
|
||||
assertEquals(Currency.USD, countryService.findByName("USA").getCurrency());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
<arquillian xmlns="http://jboss.org/schema/arquillian" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=" http://jboss.org/schema/arquillian http://jboss.org/schema/arquillian/arquillian_1_0.xsd">
|
||||
|
||||
<container qualifier="wildfly-managed" default="true">
|
||||
<configuration>
|
||||
<property name="jbossHome">target/wildfly-8.2.1.Final</property>
|
||||
<property name="serverConfig">standalone.xml</property>
|
||||
<property name="outputToConsole">true</property>
|
||||
<property name="managementPort">9990</property>
|
||||
<property name="javaVmArguments">-Djboss.http.port=8639</property>
|
||||
</configuration>
|
||||
</container>
|
||||
|
||||
<container qualifier="wildfly-remote">
|
||||
<configuration>
|
||||
<property name="managementAddress">127.0.0.1</property>
|
||||
<property name="managementPort">9990</property>
|
||||
<property name="username">admin</property>
|
||||
<property name="password">pass</property>
|
||||
<property name="allowConnectingToRunningServer">true</property>
|
||||
</configuration>
|
||||
</container>
|
||||
|
||||
</arquillian>
|
||||
@@ -0,0 +1 @@
|
||||
db-url=jdbc:h2:mem:jberet-repo;DB_CLOSE_DELAY=-1
|
||||
Reference in New Issue
Block a user