File tree 5 files changed +19
-16
lines changed
main/java/ru/mystamps/web
test/java/ru/mystamps/web/service
5 files changed +19
-16
lines changed Original file line number Diff line number Diff line change 17
17
*/
18
18
package ru .mystamps .web .config ;
19
19
20
+ import javax .inject .Inject ;
21
+
20
22
import java .util .List ;
21
23
22
24
import org .springframework .context .annotation .Bean ;
23
25
import org .springframework .context .annotation .ComponentScan ;
24
26
import org .springframework .context .annotation .Configuration ;
25
27
import org .springframework .context .MessageSource ;
26
28
import org .springframework .context .support .ReloadableResourceBundleMessageSource ;
29
+ import org .springframework .data .repository .support .DomainClassConverter ;
30
+ import org .springframework .format .support .FormattingConversionService ;
27
31
import org .springframework .scheduling .annotation .EnableScheduling ;
28
32
import org .springframework .validation .beanvalidation .LocalValidatorFactoryBean ;
29
33
import org .springframework .validation .Validator ;
@@ -122,5 +126,11 @@ public MessageSource getMessageSource() {
122
126
public MultipartResolver getMultipartResolver () {
123
127
return new CommonsMultipartResolver ();
124
128
}
125
-
129
+
130
+ @ Bean
131
+ @ Inject
132
+ public DomainClassConverter <?> getDomainClassConverter (FormattingConversionService service ) {
133
+ return new DomainClassConverter <FormattingConversionService >(service );
134
+ }
135
+
126
136
}
Original file line number Diff line number Diff line change 26
26
27
27
import org .springframework .web .multipart .MultipartFile ;
28
28
29
+ import ru .mystamps .web .entity .Country ;
29
30
import ru .mystamps .web .service .dto .AddSeriesDto ;
30
31
import ru .mystamps .web .validation .jsr303 .CatalogNumbers ;
31
32
import ru .mystamps .web .validation .jsr303 .NotEmptyFile ;
41
42
@ Getter
42
43
@ Setter
43
44
public class AddSeriesForm implements AddSeriesDto {
44
- private Integer country ;
45
+ private Country country ;
45
46
private Integer year ;
46
47
47
48
@ NotNull
Original file line number Diff line number Diff line change 32
32
33
33
import org .apache .commons .lang3 .Validate ;
34
34
35
- import ru .mystamps .web .dao .CountryDao ;
36
35
import ru .mystamps .web .dao .GibbonsCatalogDao ;
37
36
import ru .mystamps .web .dao .MichelCatalogDao ;
38
37
import ru .mystamps .web .dao .ScottCatalogDao ;
50
49
@ Service
51
50
public class SeriesService {
52
51
53
- @ Inject
54
- private CountryDao countryDao ;
55
-
56
52
@ Inject
57
53
private SeriesDao seriesDao ;
58
54
@@ -87,7 +83,7 @@ public Series add(AddSeriesDto dto) {
87
83
Series series = new Series ();
88
84
89
85
if (dto .getCountry () != null ) {
90
- series .setCountry (countryDao . findOne ( dto .getCountry () ));
86
+ series .setCountry (dto .getCountry ());
91
87
}
92
88
93
89
if (dto .getYear () != null ) {
Original file line number Diff line number Diff line change 20
20
21
21
import org .springframework .web .multipart .MultipartFile ;
22
22
23
+ import ru .mystamps .web .entity .Country ;
24
+
23
25
public interface AddSeriesDto {
24
- Integer getCountry ();
26
+ Country getCountry ();
25
27
Integer getYear ();
26
28
Integer getQuantity ();
27
29
Boolean getPerforated ();
Original file line number Diff line number Diff line change @@ -157,21 +157,15 @@ public void addShouldPassEntityToSeriesDao() {
157
157
@ Test
158
158
public void addShouldLoadAndPassCountryToSeriesDaoIfCountryPresent () {
159
159
Country expectedCountry = CountryServiceTest .getCountry ();
160
- Integer expectedId = expectedCountry .getId ();
161
- String expectedName = expectedCountry .getName ();
162
160
163
- form .setCountry (expectedId );
164
-
165
- when (countryDao .findOne (anyInt ())).thenReturn (expectedCountry );
161
+ form .setCountry (expectedCountry );
166
162
167
163
service .add (form );
168
164
169
- verify (countryDao ).findOne (eq (expectedId ));
170
165
verify (seriesDao ).save (seriesCaptor .capture ());
171
166
172
167
assertThat (seriesCaptor .getValue ().getCountry ()).isNotNull ();
173
- assertThat (seriesCaptor .getValue ().getCountry ().getId ()).isEqualTo (expectedId );
174
- assertThat (seriesCaptor .getValue ().getCountry ().getName ()).isEqualTo (expectedName );
168
+ assertThat (seriesCaptor .getValue ().getCountry ()).isEqualTo (expectedCountry );
175
169
}
176
170
177
171
@ Test
You can’t perform that action at this time.
0 commit comments