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

Commit 2543f66

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

File tree

10 files changed

+143
-2
lines changed

10 files changed

+143
-2
lines changed

pom.xml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,19 @@
101101
<version>1.2.16</version>
102102
</dependency>
103103

104+
<!--JUnit-->
105+
<dependency>
106+
<groupId>junit</groupId>
107+
<artifactId>junit</artifactId>
108+
<version>4.10</version>
109+
<scope>test</scope>
110+
</dependency>
111+
112+
<dependency>
113+
<groupId>org.springframework</groupId>
114+
<artifactId>spring-test</artifactId>
115+
<version>${org.springframework-version}</version>
116+
</dependency>
104117

105118
</dependencies>
106119

src/main/java/org/dyndns/phpusr/contactmanager/entity/Student.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ public class Student {
2828
public Student() {
2929
}
3030

31+
public Student(String name, String surname, String studGroup) {
32+
this.name = name;
33+
this.surname = surname;
34+
this.studGroup = studGroup;
35+
}
36+
3137
public Integer getId() {
3238
return id;
3339
}

src/main/resources/messages_en.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
label.name=First Name
23
label.surname=Last Name
34
label.studGroup=Email

src/main/resources/messages_ru.properties

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

src/main/webapp/WEB-INF/spring/data.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
<prop key="hibernate.show_sql">true</prop>
3636
<prop key="hibernate.dialect">${jdbc.dialect}</prop>
3737
<prop key="hibernate.connection.charSet">UTF-8</prop>
38-
<prop key="hbm2ddl.auto">create-drop</prop>
38+
<prop key="hbm2ddl.auto">update</prop>
3939
</props>
4040
</property>
4141
</bean>
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package org.dyndns.phpusr.contactmanager.service;
2+
3+
import org.dyndns.phpusr.contactmanager.entity.Student;
4+
import org.junit.After;
5+
import org.junit.Before;
6+
import org.junit.Test;
7+
import org.junit.runner.RunWith;
8+
import org.springframework.beans.factory.annotation.Autowired;
9+
import org.springframework.test.context.ContextConfiguration;
10+
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
11+
12+
/**
13+
* @author phpusr
14+
* Date: 09.04.12
15+
* Time: 22:46
16+
*/
17+
18+
@RunWith(SpringJUnit4ClassRunner.class)
19+
@ContextConfiguration(locations={"/base-context.xml"})
20+
public class StudentServiceTest {
21+
22+
@Autowired
23+
StudentService service;
24+
25+
@Before
26+
public void setUp() throws Exception {
27+
28+
}
29+
30+
@After
31+
public void tearDown() throws Exception {
32+
33+
}
34+
35+
@Test
36+
public void testAddStudent() throws Exception {
37+
service.addStudent(new Student("Ivan", "FuckOff", "Linkin Park"));
38+
}
39+
40+
@Test
41+
public void testGetStudents() throws Exception {
42+
service.getStudents();
43+
}
44+
45+
@Test
46+
public void testRemoveStudent() throws Exception {
47+
48+
}
49+
50+
@Test
51+
public void testGetStudentById() throws Exception {
52+
53+
}
54+
}

src/test/resources/base-context.xml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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+
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">
11+
<!--
12+
Root Context: определяет ресурсы, доступные всему приложению, всем сервлетам
13+
-->
14+
<!--
15+
Включаем опцию использования конфигурационных аннотаций (@Annotation-based configuration)
16+
-->
17+
<context:annotation-config/>
18+
<!--
19+
Определяем папки, в которых будем автоматически искать бины-компоненты (@Component, @Service)
20+
-->
21+
<context:component-scan base-package="org.dyndns.phpusr.contactmanager.dao"/>
22+
<context:component-scan base-package="org.dyndns.phpusr.contactmanager.service"/>
23+
24+
<tx:annotation-driven transaction-manager="transactionManager"/>
25+
<!-- Менеджер транзакций -->
26+
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
27+
<property name="sessionFactory" ref="sessionFactory"/>
28+
</bean>
29+
30+
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" p:location="/jdbc.properties"/>
31+
32+
<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+
<!-- Настройки фабрики сессий Хибернейта -->
34+
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
35+
<property name="dataSource" ref="dataSource"/>
36+
<property name="configLocation">
37+
<value>classpath:hibernate.cfg.xml</value>
38+
</property>
39+
<property name="configurationClass">
40+
<value>org.hibernate.cfg.AnnotationConfiguration</value>
41+
</property>
42+
<property name="hibernateProperties">
43+
<props>
44+
<prop key="hibernate.show_sql">true</prop>
45+
<prop key="hibernate.dialect">${jdbc.dialect}</prop>
46+
<prop key="hibernate.connection.charSet">UTF-8</prop>
47+
<prop key="hbm2ddl.auto">update</prop>
48+
</props>
49+
</property>
50+
</bean>
51+
52+
</beans>
Binary file not shown.

src/test/resources/hibernate.cfg.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version='1.0' encoding='utf-8'?>
2+
<!DOCTYPE hibernate-configuration PUBLIC
3+
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
4+
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
5+
<hibernate-configuration>
6+
<session-factory>
7+
<mapping class="org.dyndns.phpusr.contactmanager.entity.Student"/>
8+
</session-factory>
9+
</hibernate-configuration>

src/test/resources/jdbc.properties

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
jdbc.driverClassName=org.hsqldb.jdbcDriver
2+
jdbc.dialect=org.hibernate.dialect.HSQLDialect
3+
jdbc.databaseurl=jdbc:hsqldb:hsql://localhost/students
4+
jdbc.username=sa
5+
jdbc.password=

0 commit comments

Comments
 (0)