Last active
April 11, 2016 12:32
-
-
Save sengokyu/ec71c4f29eaa403c37db51da428efe53 to your computer and use it in GitHub Desktop.
(無駄に大仰な)ズンドコキヨシ with AngularJS 2, Java EE 7(JAX-RS, CDI) ref: http://qiita.com/sengoku/items/4f461dc23b2d02ae76bc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<arquillian xmlns="http://jboss.org/schema/arquillian" | |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
xsi:schemaLocation=" | |
http://jboss.org/schema/arquillian | |
http://www.jboss.org/schema/arquillian/arquillian_1_0.xsd"> | |
<container qualifier="glassfish-embedded" default="true"> | |
<configuration> | |
<property name="bindHttpPort">18181</property> | |
</configuration> | |
</container> | |
</arquillian> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
zundoko: 'zun' | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
zundoko: 'doko' | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% mvn archetype:generate \ | |
-DarchetypeArtifactId=javaee7-arquillian-archetype \ | |
-DarchetypeGroupId=org.javaee-samples \ | |
-DinteractiveMode=false -DgroupId=com.example -DartifactId=zundoko |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% mvn -Pglassfish-embedded-arquillian test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<profile> | |
<id>glassfish-embedded-arquillian</id> | |
<dependencies> | |
<dependency> | |
<groupId>org.jboss.arquillian.container</groupId> | |
<artifactId>arquillian-glassfish-embedded-3.1</artifactId> | |
<version>${version.arquillian_glassfish_embedded}</version> | |
<scope>test</scope> | |
</dependency> | |
<dependency> | |
<groupId>org.glassfish.main.extras</groupId> | |
<artifactId>glassfish-embedded-all</artifactId> | |
<version>${version.glassfish}</version> | |
<scope>test</scope> | |
</dependency> | |
</dependencies> | |
</profile> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ZunDoko { | |
private ZunDokoEnum zunDoko; | |
// コンストラクタやらsetterやらgetterやら | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public enum ZunDokoEnum { | |
zun, | |
doko; | |
public static ZunDokoEnum valueOf(boolean b) { | |
return b ? ZunDokoEnum.zun : ZunDokoEnum.doko; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ZunDokoFactory { | |
private static final ZunDokoFactory SELF = new ZunDokoFactory(); | |
private final Random random = new Random(); | |
public static ZunDoko createZunDoko() { | |
return SELF.create(); | |
} | |
private ZunDoko create() { | |
return new ZunDoko(ZunDokoEnum.valueOf(random.nextBoolean())); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ZunDokoFactoryTest { | |
/** | |
* Test of createZunDoko method, of class ZunDokoFactory. | |
*/ | |
@Test | |
public void testCreateZunDoko() { | |
System.out.println("===>>> createZunDoko"); | |
// 略 | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import javax.enterprise.inject.Produces; | |
@RequestScoped | |
public class ZunDokoProducer { | |
@Produces | |
@ZunDokoQualifier | |
public ZunDoko produceZunDoko() { | |
return ZunDokoFactory.createZunDoko(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@RunWith(Arquillian.class) | |
public class ZunDokoProducerTest { | |
@Deployment | |
public static Archive<?> createDeployment() { | |
final WebArchive war = ShrinkWrap.create(WebArchive.class, | |
ZunDokoProducerTest.class.getSimpleName() + ".war") | |
.addClass(ZunDokoProducer.class) | |
.addClass(ZunDokoFactory.class) | |
.addClass(ZunDoko.class); | |
return war; | |
} | |
@Inject | |
@ZunDokoQualifier | |
ZunDoko instance; | |
// 略 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Qualifier | |
@Retention(RUNTIME) | |
@Target({METHOD, FIELD, PARAMETER, TYPE}) | |
public @interface ZunDokoQualifier { | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example; | |
import javax.enterprise.context.RequestScoped; | |
import javax.inject.Inject; | |
import javax.ws.rs.GET; | |
import javax.ws.rs.Path; | |
import javax.ws.rs.Produces; | |
import javax.ws.rs.core.MediaType; | |
@Dependent | |
@Path("zundoko") | |
public class ZunDokoResource { | |
@Inject | |
private ZunDoko zunDoko; | |
@GET | |
@Produces(MediaType.APPLICATION_JSON) | |
public ZunDoko getZunDoko() { | |
return zunDoko; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@RunWith(Arquillian.class) | |
public class ZunDokoResourceTest { | |
@Deployment(testable = false) | |
public static Archive<?> createDeployment() { | |
// 略 | |
} | |
@ArquillianResource | |
private URI base; | |
private WebTarget target; | |
@Before | |
public void setUp() { | |
final Client client = ClientBuilder.newClient(); | |
target = client.target(base) | |
.path("webapi") | |
.register(ZunDoko.class); | |
} | |
@Test | |
public void testGetZunDoko() { | |
System.out.println("===>>> getZunDoko"); | |
// 略 | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment