Skip to content

Commit f85ac65

Browse files
committed
Fix Snapshot unit testcase.
1 parent e5b23e3 commit f85ac65

3 files changed

Lines changed: 131 additions & 1 deletion

File tree

server/test/com/cloud/snapshot/SnapshotDaoTest.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,32 @@
2020

2121
import javax.inject.Inject;
2222

23+
import org.junit.Before;
24+
import org.junit.Test;
25+
import org.junit.runner.RunWith;
26+
import org.springframework.test.context.ContextConfiguration;
27+
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
28+
2329
import com.cloud.storage.Snapshot;
2430
import com.cloud.storage.SnapshotVO;
2531
import com.cloud.storage.dao.SnapshotDaoImpl;
32+
import com.cloud.utils.component.ComponentContext;
2633

2734

2835
import junit.framework.Assert;
2936
import junit.framework.TestCase;
3037

38+
@RunWith(SpringJUnit4ClassRunner.class)
39+
@ContextConfiguration(locations = "classpath:/SnapshotDaoTestContext.xml")
3140
public class SnapshotDaoTest extends TestCase {
3241
@Inject SnapshotDaoImpl dao;
33-
42+
43+
@Before
44+
public void setup() throws Exception {
45+
ComponentContext.initComponentsLifeCycle();
46+
}
47+
48+
@Test
3449
public void testListBy() {
3550
List<SnapshotVO> snapshots = dao.listByInstanceId(3, Snapshot.Status.BackedUp);
3651
for(SnapshotVO snapshot : snapshots) {
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
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+
18+
package com.cloud.snapshot;
19+
20+
import java.io.IOException;
21+
22+
import org.springframework.context.annotation.ComponentScan;
23+
import org.springframework.context.annotation.ComponentScan.Filter;
24+
import org.springframework.context.annotation.Configuration;
25+
import org.springframework.context.annotation.FilterType;
26+
import org.springframework.core.type.classreading.MetadataReader;
27+
import org.springframework.core.type.classreading.MetadataReaderFactory;
28+
import org.springframework.core.type.filter.TypeFilter;
29+
30+
import com.cloud.cluster.agentlb.dao.HostTransferMapDaoImpl;
31+
import com.cloud.dc.dao.ClusterDaoImpl;
32+
import com.cloud.dc.dao.HostPodDaoImpl;
33+
import com.cloud.host.dao.HostDaoImpl;
34+
import com.cloud.host.dao.HostDetailsDaoImpl;
35+
import com.cloud.host.dao.HostTagsDaoImpl;
36+
import com.cloud.storage.dao.SnapshotDaoImpl;
37+
import com.cloud.storage.dao.VolumeDaoImpl;
38+
import com.cloud.tags.dao.ResourceTagsDaoImpl;
39+
import com.cloud.utils.component.SpringComponentScanUtils;
40+
import com.cloud.vm.dao.NicDaoImpl;
41+
import com.cloud.vm.dao.VMInstanceDaoImpl;
42+
43+
@Configuration
44+
@ComponentScan(basePackageClasses={
45+
SnapshotDaoImpl.class,
46+
ResourceTagsDaoImpl.class,
47+
VMInstanceDaoImpl.class,
48+
VolumeDaoImpl.class,
49+
NicDaoImpl.class,
50+
HostDaoImpl.class,
51+
HostDetailsDaoImpl.class,
52+
HostTagsDaoImpl.class,
53+
HostTransferMapDaoImpl.class,
54+
ClusterDaoImpl.class,
55+
HostPodDaoImpl.class},
56+
includeFilters={@Filter(value=SnapshotDaoTestConfiguration.Library.class, type=FilterType.CUSTOM)},
57+
useDefaultFilters=false
58+
)
59+
public class SnapshotDaoTestConfiguration {
60+
61+
62+
public static class Library implements TypeFilter {
63+
64+
@Override
65+
public boolean match(MetadataReader mdr, MetadataReaderFactory arg1) throws IOException {
66+
mdr.getClassMetadata().getClassName();
67+
ComponentScan cs = SnapshotDaoTestConfiguration.class.getAnnotation(ComponentScan.class);
68+
return SpringComponentScanUtils.includedInBasePackageClasses(mdr.getClassMetadata().getClassName(), cs);
69+
}
70+
71+
}
72+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor
2+
license agreements. See the NOTICE file distributed with this work for additional
3+
information regarding copyright ownership. The ASF licenses this file to
4+
you under the Apache License, Version 2.0 (the "License"); you may not use
5+
this file except in compliance with the License. You may obtain a copy of
6+
the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required
7+
by applicable law or agreed to in writing, software distributed under the
8+
License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
9+
OF ANY KIND, either express or implied. See the License for the specific
10+
language governing permissions and limitations under the License. -->
11+
<beans xmlns="http://www.springframework.org/schema/beans"
12+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
13+
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop"
14+
xsi:schemaLocation="http://www.springframework.org/schema/beans
15+
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
16+
http://www.springframework.org/schema/tx
17+
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
18+
http://www.springframework.org/schema/aop
19+
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
20+
http://www.springframework.org/schema/context
21+
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
22+
23+
<context:annotation-config />
24+
25+
<!-- @DB support -->
26+
<aop:config proxy-target-class="true">
27+
<aop:aspect id="dbContextBuilder" ref="transactionContextBuilder">
28+
<aop:pointcut id="captureAnyMethod" expression="execution(* *(..))" />
29+
30+
<aop:around pointcut-ref="captureAnyMethod" method="AroundAnyMethod" />
31+
</aop:aspect>
32+
33+
</aop:config>
34+
35+
<bean id="transactionContextBuilder" class="com.cloud.utils.db.TransactionContextBuilder" />
36+
<bean id="componentContext" class="com.cloud.utils.component.ComponentContext"/>
37+
<!-- bean id="snapshotDaoImpl" class="com.cloud.storage.dao.SnapshotDaoImpl"/-->
38+
<bean id="TestConfiguration"
39+
class="com.cloud.snapshot.SnapshotDaoTestConfiguration" />
40+
<bean class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor" >
41+
<property name="requiredParameterValue" value="false" />
42+
</bean>
43+
</beans>

0 commit comments

Comments
 (0)