Revert "Spring Groovy Config with fixed pom" (#1209)

This commit is contained in:
Grzegorz Piwowarek 2017-02-21 07:35:07 +01:00 committed by GitHub
parent a75ed7e70a
commit d3d11a18f3
22 changed files with 0 additions and 449 deletions

View File

@ -1,48 +0,0 @@
package com.baeldung.java_bean_injection;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.baeldung.java_bean_injection.*;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import junit.framework.TestResult;
import junit.framework.TestFailure;
import java.util.Enumeration;
/**
* Bean Injection Test Application
*
*/
public class App
{
public static void main( String[] args )
{
TestResult result = new TestResult();
AppTest.suite().run(result);
System.out.println(String.format("Tests: %d",result.runCount()));
System.out.println(String.format("Errors: %d",result.errorCount()));
System.out.println(String.format("Failures: %d",result.failureCount()));
if(result.failureCount() > 0){
Enumeration<TestFailure> failures = result.failures();
int failNum = 0;
TestFailure failure = null;
while(failures.hasMoreElements()){
failure = failures.nextElement();
System.out.println(failure.exceptionMessage());
System.out.println(String.format("Test Failure %d\n",failNum));
System.out.println(failure.trace());
System.out.print("\n");
}
}
}
}

View File

@ -1,23 +0,0 @@
package com.baeldung.java_bean_injection;
import org.springframework.beans.factory.annotation.*;
import org.springframework.context.annotation.*;
import org.springframework.stereotype.*;
import com.baeldung.java_bean_injection.*;
@Configuration
@PropertySource(value="classpath:inject.properties")
@Import(ImportConfig.class)
public class AppConfig {
@Value("${contructor.arg1}") String constructorArg;
@Bean
public InjectedClass injectedClass(){
InjectedClass ic = new InjectedClass(constructorArg);
ic.setMyInt(10);
ic.setTestString("test");
return ic;
}
}

View File

@ -1,52 +0,0 @@
package com.baeldung.java_bean_injection;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.baeldung.java_bean_injection.*;
import java.io.File;
import java.util.Scanner;
/**
* Unit test for simple App.
*/
public class AppTest extends TestCase{
/**
* Create the test case
*
* @param testName name of the test case
*/
public AppTest( String testName )
{
super( testName );
}
/**
* @return the suite of tests being tested
*/
public static Test suite()
{
return new TestSuite( AppTest.class );
}
/**
* Rigourous Test :-)
*/
public void testApp()
{
AnnotationConfigApplicationContext context= new AnnotationConfigApplicationContext();
context.register(AppConfig.class);
context.refresh();
InjectedClass injectedClass = (InjectedClass) context.getBean(InjectedClass.class);
assertTrue(injectedClass.getMyInt() == 10);
assertTrue(injectedClass.getTestString().equals("test"));
assertNotNull(injectedClass.obj);
assertTrue(injectedClass.myConstructorArg.equals("test"));
}
}

View File

@ -1,6 +0,0 @@
package com.baeldung.java_bean_injection;
public class AutowireObject {
}

View File

@ -1,20 +0,0 @@
package com.baeldung.java_bean_injection;
import org.springframework.context.annotation.*;
import com.baeldung.java_bean_injection.*;
@Configuration
public class ImportConfig {
@Bean(name="autobean")
public AutowireObject autowireObject(){
return new AutowireObject();
}
@Bean(name="autobean2")
public AutowireObject autowireObject2(){
return new AutowireObject();
}
}

View File

@ -1,39 +0,0 @@
package com.baeldung.java_bean_injection;
import org.springframework.beans.factory.annotation.*;
import org.springframework.context.annotation.*;
import com.baeldung.java_bean_injection.*;
public class InjectedClass {
private int myInt;
private String testString;
String myConstructorArg;
@Autowired
@Qualifier("autobean")
AutowireObject obj;
public InjectedClass(String constArg){
this.myConstructorArg = constArg;
}
public void setMyInt(int myInt){
this.myInt = myInt;
}
public void setTestString(String testString){
this.testString = testString;
}
public int getMyInt(){
return this.myInt;
}
public String getTestString(){
return this.testString;
}
}

View File

@ -1 +0,0 @@
/target/

View File

@ -1,4 +0,0 @@
eclipse.preferences.version=1
encoding//src/main/java=UTF-8
encoding//src/test/java=UTF-8
encoding/<project>=UTF-8

View File

@ -1,5 +0,0 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
org.eclipse.jdt.core.compiler.compliance=1.5
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.source=1.5

View File

@ -1,2 +0,0 @@
eclipse.preferences.version=1
groovy.compiler.level=24

View File

@ -1,4 +0,0 @@
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1

View File

@ -1,9 +0,0 @@
import com.baeldung.spring_groovy_config.TestClass
beans{
testString String, 'Test String'
testClass(TestClass){
beanDefinition ->
beanDefinition.constructorArgs = ["Test String",10.2]
}
}

View File

@ -1,5 +0,0 @@
import com.baeldung.spring_groovy_config.TestClassB
beans{
testClassB(TestClassB,testStringB:"Test String",testIntB:10.2)
}

View File

@ -1,8 +0,0 @@
import com.baeldung.spring_groovy_config.TestClassB
beans{
testClassB(TestClassB){
testStringB = "Test String"
testIntB = 10
}
}

View File

@ -1,10 +0,0 @@
import com.baeldung.spring_groovy_config.GroovyClass
import com.baeldung.spring_groovy_config.ClassWithRef
beans{
groovyClass(GroovyClass, groovyInt:5)
classWithRef(ClassWithRef){
myClass = groovyClass
}
}

View File

@ -1,67 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.baeldung</groupId>
<artifactId>spring-groovy-config</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>spring-groovy-config</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<!-- 2.8.0-01 and later require maven-compiler-plugin 3.1 or higher -->
<version>3.1</version>
<configuration>
<compilerId>groovy-eclipse-compiler</compilerId>
</configuration>
<dependencies>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-eclipse-compiler</artifactId>
<version>2.9.1-01</version>
</dependency>
<!-- for 2.8.0-01 and later you must have an explicit dependency on groovy-eclipse-batch -->
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-eclipse-batch</artifactId>
<version>2.3.7-01</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>2.4.8</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.3.6.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>4.3.6.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>4.3.6.RELEASE</version>
</dependency>
</dependencies>
</project>

View File

@ -1,18 +0,0 @@
package com.baeldung.spring_groovy_config;
import org.springframework.stereotype.Component;
import com.baeldung.spring_groovy_config.GroovyClass;
@Component
public class ClassWithRef {
private GroovyClass myClass = null;
public void setMyClass(GroovyClass myClass){
this.myClass = myClass;
}
public GroovyClass getMyClass(){
return this.myClass;
}
}

View File

@ -1,9 +0,0 @@
package com.baeldung.spring_groovy_config
class GroovyClass {
int groovyInt = 0
def getGroovyInt(){
return groovyInt
}
}

View File

@ -1,14 +0,0 @@
package com.baeldung.spring_groovy_config;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.GenericGroovyApplicationContext;
public class MainApp {
public static void main(String[] args){
ApplicationContext context = new GenericGroovyApplicationContext("file:config/groovyTestWithRefBean.groovy");
ClassWithRef test = (ClassWithRef) context.getBean("classWithRef");
}
}

View File

@ -1,22 +0,0 @@
package com.baeldung.spring_groovy_config;
import org.springframework.stereotype.Component;
@Component
public class TestClass {
private String testString;
private double testDouble;
public TestClass(String testString, double testDouble){
this.testString = testString;
this.testDouble = testDouble;
}
public String getTestString(){
return this.testString;
}
public double getTestDouble(){
return this.testDouble;
}
}

View File

@ -1,26 +0,0 @@
package com.baeldung.spring_groovy_config;
import org.springframework.stereotype.Component;
@Component
public class TestClassB {
private String testStringB;
private int testIntB;
public void setTestStringB(String testStringB){
this.testStringB = testStringB;
}
public String getTestStringB(){
return this.testStringB;
}
public void setTestIntB(int testIntB){
this.testIntB = testIntB;
}
public int getTestIntB(){
return this.testIntB;
}
}

View File

@ -1,57 +0,0 @@
package com.baeldung.spring_groovy_config;
import com.baeldung.spring_groovy_config.*;
import groovy.lang.Binding;
import junit.framework.TestCase;
import static org.junit.Assert.*;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;
import org.springframework.context.support.GenericApplicationContext;
import org.springframework.context.support.GenericGroovyApplicationContext;
import org.springframework.core.env.ConfigurableEnvironment;
/**
* Spring Framework Tests for Groovy.
*/
public class AppTest{
@Test
public void testSimple(){
ApplicationContext context = new GenericGroovyApplicationContext("file:config/groovyContextWithConstructor.groovy");
TestClass test = (TestClass) context.getBean("testClass");
assertNotNull(test.getTestString());
assertEquals(test.getTestString(),"Test String");
assertTrue(test.getTestDouble() == 10.2);
String testString = context.getBean("testString",String.class);
assertEquals(testString,"Test String");
}
@Test
public void testProperties(){
ApplicationContext context = new GenericGroovyApplicationContext("file:config/groovyPropConfig.groovy");
TestClassB test = (TestClassB) context.getBean("testClassB");
assertNotNull(test.getTestStringB());
assertEquals(test.getTestStringB(),"Test String");
assertTrue(test.getTestIntB() == 10);
}
@Test
public void testPropertiesWithClosure(){
ApplicationContext context = new GenericGroovyApplicationContext("file:config/groovyPropConfigWithClosure.groovy");
TestClassB test = (TestClassB) context.getBean("testClassB");
assertNotNull(test.getTestStringB());
assertEquals(test.getTestStringB(),"Test String");
assertTrue(test.getTestIntB() == 10);
}
@Test
public void testWithRef(){
ApplicationContext context = new GenericGroovyApplicationContext("file:config/groovyTestWithRefBean.groovy");
ClassWithRef test = (ClassWithRef) context.getBean("classWithRef");
assertEquals(test.getMyClass().getGroovyInt(),5);
}
}