Skip to content

Commit 16ed870

Browse files
committed
Test of using Spring DI to implement Basic/Premium configuration
1 parent dcf3790 commit 16ed870

8 files changed

Lines changed: 145 additions & 2 deletions

File tree

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
package com.cloud.utils;
18+
19+
import org.springframework.stereotype.Component;
20+
21+
@Component
22+
public class DummyImpl implements DummyInterface {
23+
24+
@Override
25+
public void foo() {
26+
System.out.println("Basic foo implementation");
27+
}
28+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
package com.cloud.utils;
18+
19+
public interface DummyInterface {
20+
void foo();
21+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
package com.cloud.utils;
18+
19+
import org.springframework.context.annotation.Primary;
20+
import org.springframework.stereotype.Component;
21+
22+
@Component
23+
@Primary
24+
public class DummyPremiumImpl implements DummyInterface {
25+
26+
@Override
27+
public void foo() {
28+
System.out.println("Premium foo implementation");
29+
}
30+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
package com.cloud.utils;
18+
19+
import org.junit.Test;
20+
import org.junit.runner.RunWith;
21+
import org.springframework.beans.factory.annotation.Autowired;
22+
import org.springframework.test.context.ContextConfiguration;
23+
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
24+
25+
@RunWith(SpringJUnit4ClassRunner.class)
26+
@ContextConfiguration(locations="classpath:/com/cloud/utils/QualifierTestContext.xml")
27+
public class QualifierTest {
28+
29+
@Autowired
30+
DummyInterface _dummy;
31+
32+
@Test
33+
public void test() {
34+
_dummy.foo();
35+
}
36+
}

utils/test/com/cloud/utils/db/DbAnnotatedBase.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@
1616
// under the License.
1717
package com.cloud.utils.db;
1818

19+
20+
import javax.annotation.PostConstruct;
21+
22+
import junit.framework.Assert;
23+
1924
import org.apache.log4j.Logger;
2025
import org.springframework.stereotype.Component;
2126

@@ -24,6 +29,11 @@
2429
public class DbAnnotatedBase {
2530
private static final Logger s_logger = Logger.getLogger(DbAnnotatedBase.class);
2631

32+
@PostConstruct
33+
public void initTest() {
34+
Assert.assertTrue(true);
35+
}
36+
2737
public void MethodWithClassDbAnnotated() {
2838
s_logger.info("called");
2939
}

utils/test/com/cloud/utils/db/TransactionContextBuilderTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
99

1010
@RunWith(SpringJUnit4ClassRunner.class)
11-
@ContextConfiguration(locations="classpath:/transactioncontextBuilderTest.xml")
11+
@ContextConfiguration(locations="classpath:/com/cloud/utils/db/transactioncontextBuilderTest.xml")
1212
public class TransactionContextBuilderTest {
1313

1414
@Inject
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<beans xmlns="http://www.springframework.org/schema/beans"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xmlns:context="http://www.springframework.org/schema/context"
6+
xmlns:tx="http://www.springframework.org/schema/tx"
7+
xmlns:aop="http://www.springframework.org/schema/aop"
8+
xsi:schemaLocation="http://www.springframework.org/schema/beans
9+
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
10+
http://www.springframework.org/schema/tx
11+
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
12+
http://www.springframework.org/schema/aop
13+
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
14+
http://www.springframework.org/schema/context
15+
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
16+
<context:annotation-config />
17+
<context:component-scan base-package="org.apache.cloudstack, com.cloud" />
18+
19+
</beans>

utils/test/resources/transactionContextBuilderTest.xml renamed to utils/test/resources/com/cloud/utils/db/transactionContextBuilderTest.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
http://www.springframework.org/schema/context
1515
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
1616
<context:annotation-config />
17-
1817
<context:component-scan base-package="org.apache.cloudstack, com.cloud" />
1918

2019
<aop:config proxy-target-class="true">

0 commit comments

Comments
 (0)