Skip to content
This repository was archived by the owner on Jan 18, 2019. It is now read-only.

Commit ce86a80

Browse files
committed
Добавил тестовые дао и сервис, поменял библиотеки (тест все еще не работает)
1 parent 2543f66 commit ce86a80

File tree

15 files changed

+153
-21
lines changed

15 files changed

+153
-21
lines changed

pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,17 @@
2424
<dependency>
2525
<groupId>org.hibernate</groupId>
2626
<artifactId>hibernate-core</artifactId>
27-
<version>3.3.2.GA</version>
27+
<version>3.5.6-Final</version>
2828
</dependency>
2929
<dependency>
3030
<groupId>org.hibernate</groupId>
3131
<artifactId>hibernate-annotations</artifactId>
32-
<version>3.3.1.GA</version>
32+
<version>3.2.0.ga</version>
3333
</dependency>
3434
<dependency>
3535
<groupId>org.hibernate</groupId>
3636
<artifactId>hibernate-commons-annotations</artifactId>
37-
<version>3.3.0.ga</version>
37+
<version>3.2.0.Final</version>
3838
</dependency>
3939

4040
<!--Spring Transactional-->

src/main/java/org/dyndns/phpusr/contactmanager/dao/StudentDaoImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* Time: 20:18
1414
*/
1515

16-
@Repository
16+
@Repository("studentDaoDefault")
1717
public class StudentDaoImpl implements StudentDao {
1818

1919
@Autowired

src/main/java/org/dyndns/phpusr/contactmanager/service/StudentServiceImpl.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import org.dyndns.phpusr.contactmanager.dao.StudentDao;
44
import org.dyndns.phpusr.contactmanager.entity.Student;
55
import org.springframework.beans.factory.annotation.Autowired;
6+
import org.springframework.beans.factory.annotation.Qualifier;
67
import org.springframework.stereotype.Service;
78
import org.springframework.transaction.annotation.Transactional;
89

@@ -14,10 +15,11 @@
1415
* Time: 21:09
1516
*/
1617

17-
@Service
18+
@Service("studentServiceDefault")
1819
public class StudentServiceImpl implements StudentService {
1920

2021
@Autowired
22+
@Qualifier("StudentTestDao")
2123
StudentDao dao;
2224

2325
@Transactional

src/main/java/org/dyndns/phpusr/contactmanager/service/Constants.java renamed to src/main/java/org/dyndns/phpusr/contactmanager/util/Constants.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package org.dyndns.phpusr.contactmanager.service;
1+
package org.dyndns.phpusr.contactmanager.util;
22

33
import org.springframework.stereotype.Service;
44

src/main/java/org/dyndns/phpusr/contactmanager/web/StudentController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package org.dyndns.phpusr.contactmanager.web;
22

33
import org.dyndns.phpusr.contactmanager.entity.Student;
4-
import org.dyndns.phpusr.contactmanager.service.Constants;
54
import org.dyndns.phpusr.contactmanager.service.StudentService;
5+
import org.dyndns.phpusr.contactmanager.util.Constants;
66
import org.springframework.beans.factory.annotation.Autowired;
77
import org.springframework.stereotype.Controller;
88
import org.springframework.validation.BindingResult;

src/main/resources/messages_ru.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
2-
label.name=Имя
1+
2+
label.name=Имя
33
label.surname=Фамилия
44
label.studGroup=Группа
55
label.addStudent=Добавить контакт

src/main/webapp/WEB-INF/views/student.jsp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<%@ page import="org.dyndns.phpusr.contactmanager.service.Constants" %>
1+
<%@ page import="org.dyndns.phpusr.contactmanager.util.Constants" %>
22
<%@ page language="java" contentType="text/html; charset=utf8"
33
pageEncoding="utf8"%>
44
<%@taglib uri="http://www.springframework.org/tags" prefix="spring"%>

src/main/webapp/index.jsp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<%@ page import="org.dyndns.phpusr.contactmanager.service.Constants" %>
1+
<%@ page import="org.dyndns.phpusr.contactmanager.util.Constants" %>
22
<%--
33
Created by IntelliJ IDEA.
44
User: phpusr
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package org.dyndns.phpusr.contactmanager.dao;
2+
3+
import org.dyndns.phpusr.contactmanager.entity.Student;
4+
import org.springframework.stereotype.Repository;
5+
6+
import java.util.List;
7+
8+
/**
9+
* @author phpusr
10+
* Date: 10.04.12
11+
* Time: 21:16
12+
*/
13+
14+
@Repository("StudentTestDao")
15+
public class StudenDaoMock implements StudentDao {
16+
public void addStudent(Student student) {
17+
//To change body of implemented methods use File | Settings | File Templates.
18+
}
19+
20+
public List<Student> getStudents() {
21+
return null; //To change body of implemented methods use File | Settings | File Templates.
22+
}
23+
24+
public void removeStudent(Student student) {
25+
//To change body of implemented methods use File | Settings | File Templates.
26+
}
27+
28+
public Student getStudentById(Integer id) {
29+
return null; //To change body of implemented methods use File | Settings | File Templates.
30+
}
31+
}

src/test/java/org/dyndns/phpusr/contactmanager/service/StudentServiceTest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import org.junit.Test;
77
import org.junit.runner.RunWith;
88
import org.springframework.beans.factory.annotation.Autowired;
9+
import org.springframework.beans.factory.annotation.Qualifier;
910
import org.springframework.test.context.ContextConfiguration;
1011
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
1112

@@ -16,10 +17,11 @@
1617
*/
1718

1819
@RunWith(SpringJUnit4ClassRunner.class)
19-
@ContextConfiguration(locations={"/base-context.xml"})
20+
@ContextConfiguration(locations={"/root-context.xml"})
2021
public class StudentServiceTest {
2122

2223
@Autowired
24+
@Qualifier("studentServiceDefault")
2325
StudentService service;
2426

2527
@Before
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package org.dyndns.phpusr.contactmanager.service;
2+
3+
import org.dyndns.phpusr.contactmanager.entity.Student;
4+
import org.springframework.stereotype.Service;
5+
6+
import java.util.List;
7+
8+
/**
9+
* @author phpusr
10+
* Date: 10.04.12
11+
* Time: 21:24
12+
*/
13+
14+
@Service("hello")
15+
public class StudentServiceTestImpl implements StudentService {
16+
17+
public void addStudent(Student student) {
18+
//To change body of implemented methods use File | Settings | File Templates.
19+
}
20+
21+
public List<Student> getStudents() {
22+
return null; //To change body of implemented methods use File | Settings | File Templates.
23+
}
24+
25+
public void removeStudent(Student student) {
26+
//To change body of implemented methods use File | Settings | File Templates.
27+
}
28+
29+
public Student getStudentById(Integer id) {
30+
return null; //To change body of implemented methods use File | Settings | File Templates.
31+
}
32+
}

src/test/resources/base-context.xml

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,8 @@
44
xmlns:context="http://www.springframework.org/schema/context"
55
xsi:schemaLocation="http://www.springframework.org/schema/beans
66
http://www.springframework.org/schema/beans/spring-beans.xsd
7-
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
8-
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd"
9-
xmlns:p="http://www.springframework.org/schema/p"
10-
xmlns:tx="http://www.springframework.org/schema/tx">
7+
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"
8+
>
119
<!--
1210
Root Context: определяет ресурсы, доступные всему приложению, всем сервлетам
1311
-->
@@ -21,16 +19,16 @@
2119
<context:component-scan base-package="org.dyndns.phpusr.contactmanager.dao"/>
2220
<context:component-scan base-package="org.dyndns.phpusr.contactmanager.service"/>
2321

24-
<tx:annotation-driven transaction-manager="transactionManager"/>
25-
<!-- Менеджер транзакций -->
22+
<!--<tx:annotation-driven transaction-manager="transactionManager"/>
23+
&lt;!&ndash; Менеджер транзакций &ndash;&gt;
2624
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
2725
<property name="sessionFactory" ref="sessionFactory"/>
2826
</bean>
2927
30-
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" p:location="/jdbc.properties"/>
28+
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" p:location="jdbc.properties"/>
3129
3230
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource" p:driverClassName="${jdbc.driverClassName}" p:url="${jdbc.databaseurl}" p:username="${jdbc.username}" p:password="${jdbc.password}"/>
33-
<!-- Настройки фабрики сессий Хибернейта -->
31+
&lt;!&ndash; Настройки фабрики сессий Хибернейта &ndash;&gt;
3432
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
3533
<property name="dataSource" ref="dataSource"/>
3634
<property name="configLocation">
@@ -47,6 +45,6 @@
4745
<prop key="hbm2ddl.auto">update</prop>
4846
</props>
4947
</property>
50-
</bean>
48+
</bean>-->
5149

5250
</beans>

src/test/resources/data.xml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?xml version='1.0' encoding='utf-8'?>
2+
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xmlns:p="http://www.springframework.org/schema/p" xmlns:tx="http://www.springframework.org/schema/tx"
4+
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
5+
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
6+
<!--
7+
Настраивает управление транзакциями с помощью аннотации @Transactional
8+
-->
9+
<tx:annotation-driven transaction-manager="transactionManager"/>
10+
<!-- Менеджер транзакций -->
11+
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
12+
<property name="sessionFactory" ref="sessionFactory"/>
13+
</bean>
14+
<bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
15+
<property name="basename" value="classpath:messages"/>
16+
<property name="defaultEncoding" value="utf-8"/>
17+
</bean>
18+
<!--
19+
Настройки бина dataSource будем хранить в отдельном файле
20+
-->
21+
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" p:location="/jdbc.properties"/>
22+
<!-- Непосредственно бин dataSource -->
23+
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource" p:driverClassName="${jdbc.driverClassName}" p:url="${jdbc.databaseurl}" p:username="${jdbc.username}" p:password="${jdbc.password}"/>
24+
<!-- Настройки фабрики сессий Хибернейта -->
25+
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
26+
<property name="dataSource" ref="dataSource"/>
27+
<property name="configLocation">
28+
<value>classpath:hibernate.cfg.xml</value>
29+
</property>
30+
<property name="configurationClass">
31+
<value>org.hibernate.cfg.AnnotationConfiguration</value>
32+
</property>
33+
<property name="hibernateProperties">
34+
<props>
35+
<prop key="hibernate.show_sql">true</prop>
36+
<prop key="hibernate.dialect">${jdbc.dialect}</prop>
37+
<prop key="hibernate.connection.charSet">UTF-8</prop>
38+
<prop key="hbm2ddl.auto">update</prop>
39+
</props>
40+
</property>
41+
</bean>
42+
</beans>
Binary file not shown.

src/test/resources/root-context.xml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?xml version='1.0' encoding='utf-8'?>
2+
<beans xmlns="http://www.springframework.org/schema/beans"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xmlns:context="http://www.springframework.org/schema/context"
5+
xsi:schemaLocation="http://www.springframework.org/schema/beans
6+
http://www.springframework.org/schema/beans/spring-beans.xsd
7+
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
8+
<!--
9+
Root Context: определяет ресурсы, доступные всему приложению, всем сервлетам
10+
-->
11+
<!--
12+
Включаем опцию использования конфигурационных аннотаций (@Annotation-based configuration)
13+
-->
14+
<context:annotation-config/>
15+
<!--
16+
Определяем папки, в которых будем автоматически искать бины-компоненты (@Component, @Service)
17+
-->
18+
<context:component-scan base-package="org.dyndns.phpusr.contactmanager.dao"/>
19+
<context:component-scan base-package="org.dyndns.phpusr.contactmanager.service"/>
20+
<!--
21+
Файл с настройками ресурсов для работы с данными (Data Access Resources)
22+
-->
23+
<import resource="data.xml"/>
24+
25+
</beans>

0 commit comments

Comments
 (0)