|
3 | 3 | import org.junit.Before;
|
4 | 4 | import org.junit.Test;
|
5 | 5 | import org.junit.runner.RunWith;
|
6 |
| -import org.mockito.InjectMocks; |
7 | 6 | import org.mockito.Mock;
|
8 | 7 | import org.mockito.MockitoAnnotations;
|
9 | 8 | import org.springframework.beans.factory.annotation.Autowired;
|
10 |
| -import org.springframework.beans.factory.annotation.Qualifier; |
11 | 9 | import org.springframework.boot.test.context.SpringBootTest;
|
12 | 10 | import org.springframework.context.annotation.Bean;
|
13 | 11 | import org.springframework.context.annotation.Configuration;
|
14 | 12 | import org.springframework.context.annotation.Primary;
|
15 |
| -import org.springframework.context.support.ClassPathXmlApplicationContext; |
16 |
| -import org.springframework.dao.support.DaoSupport; |
17 |
| -import org.springframework.test.context.ActiveProfiles; |
18 | 13 | import org.springframework.test.context.ContextConfiguration;
|
19 | 14 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
20 |
| -import org.springframework.test.context.junit4.SpringRunner; |
21 |
| - |
22 | 15 | import com.Polodz.View.MainWindow;
|
23 |
| -import com.Polodz.controller.Controller; |
24 |
| -import com.Polodz.controller.IController; |
25 | 16 | import com.Polodz.controller.MainController;
|
26 |
| -import com.Polodz.model.MembersBeanFactory; |
27 |
| -import com.Polodz.model.MembersDAO; |
| 17 | +import com.Polodz.model.IItem; |
| 18 | +import com.Polodz.service.ITelnet; |
| 19 | +import com.Polodz.service.TelnetConnector; |
28 | 20 |
|
29 |
| -import junit.framework.Assert; |
| 21 | +import org.junit.Assert; |
30 | 22 | import static org.mockito.Mockito.*;
|
31 | 23 |
|
32 |
| -import org.mockito.runners.MockitoJUnitRunner; |
33 |
| - |
34 |
| -@SuppressWarnings("deprecation") |
35 |
| -//@RunWith(MockitoJUnitRunner.class) |
| 24 | +import java.util.List; |
36 | 25 |
|
37 |
| -@RunWith(SpringJUnit4ClassRunner.class)//(SpringJUnit4ClassRunner.class)//(SpringRunner.class) |
| 26 | +@RunWith(SpringJUnit4ClassRunner.class) |
38 | 27 | @ContextConfiguration(locations={"file:src/test/resources/Grown-mainContext.xml"}, loader=CustomSpringApplicationContextLoader.class)
|
39 | 28 | @SpringBootTest
|
40 |
| -//@ActiveProfiles("test") |
41 |
| -//@ContextConfiguration(locations = {"classpath*:spring/mocksContext.xml"}) |
42 |
| -//@ContextConfiguration |
43 |
| -//@ActiveProfiles("test") |
44 | 29 | @Configuration
|
| 30 | +//@ActiveProfiles("test") |
45 | 31 | public class GrownApplicationTests {
|
46 |
| - private ClassPathXmlApplicationContext context; |
47 |
| - //@InjectMocks |
| 32 | + |
48 | 33 | @Autowired
|
49 | 34 | private MainController mainControler;
|
50 |
| - //@InjectMocks |
51 |
| - @Autowired |
52 |
| - private MembersDAO mtcDAO; |
53 |
| -// private BtcsBeanFactory btcsBeanFactory; |
| 35 | + |
| 36 | +// @Autowired |
| 37 | +// private MembersDAO mtcDAO; |
| 38 | +// private BeanFactory BeanFactory; |
54 | 39 | @Mock
|
55 |
| - private IController IController; |
| 40 | + private ITelnet telnetHandler; |
56 | 41 |
|
57 | 42 | @Mock
|
58 | 43 | private MainWindow disableWindow;
|
59 | 44 |
|
60 | 45 | @Before
|
61 | 46 | public void setup(){
|
62 |
| - MockitoAnnotations.initMocks(this); //@RunWith(MockitoJUnitRunner.class). |
63 |
| - //context= new ClassPathXmlApplicationContext("file:src/EasyMTC-contextTestBF.xml");//file:classpath* |
64 |
| - //mtcDAO= context.getBean("mtcDAOF",MtcDAO.class); |
65 |
| - //mainControler= context.getBean("mainController",MainController.class); |
66 |
| - //mtcDAO= (MtcDAO)context.getBean("mtcDAO"); |
67 |
| - |
68 |
| - when(IController.execute("list")).thenReturn("test\ntest\ntest\ntest\ntest\ntest"); |
69 |
| - when(IController.execute("test items")).thenReturn("mtest\nmtest\nmtest\nmtest\nmtest\nmtest"); |
70 |
| - reset(IController); |
71 |
| - //btcsBeanFactory= context.getBean(BtcsBeanFactory.class); |
| 47 | + MockitoAnnotations.initMocks(this); |
| 48 | + when(telnetHandler.get("list")).thenReturn("test\ntest1\ntest2\ntest3\ntest4\ntest5"); |
| 49 | + when(telnetHandler.get("test")).thenReturn("mtest\nmtest1\nmtest2\nmtest3\nmtest4\nmtest5"); |
| 50 | + reset(telnetHandler); |
| 51 | + //BeanFactory= context.getBean(BeanFactory.class); |
72 | 52 | }
|
73 |
| - @SuppressWarnings("deprecation") |
| 53 | + |
74 | 54 | @Test
|
75 |
| - public void contextLoads() { |
| 55 | + public void membersLoad() { |
| 56 | + this.serverResponse(); |
| 57 | + Assert.assertNotNull(mainControler.getMembersDAO().getMembersAudience()); |
76 | 58 | Assert.assertEquals(mainControler.listAll().size(), 6);
|
77 |
| - Assert.assertEquals(mainControler.listAll().get(1).getName(), "test"); |
78 |
| - Assert.assertEquals(mainControler.getMtcResponse("list"), "test\ntest\ntest\ntest\ntest\ntest"); |
79 |
| - //Assert.assertEquals(mtcDAO.getALL().length, 86); |
80 |
| - //Assert.assertEquals(mtcDAO.getALL()[85].getName(), "bsc183"); //Aware of spaces! |
81 |
| - //Assert.assertEquals(btcsBeanFactory.getObjectType(), MtcDAO.class); |
| 59 | + Assert.assertEquals(mainControler.listAll().get(1).getName(), "test1"); |
| 60 | + Assert.assertEquals(mainControler.listAll().get(1).getItems().get(1).getName(),"mtest1"); |
| 61 | + //Assert.assertEquals(BeanFactory.getObjectType(), DAO.class); |
| 62 | + } |
| 63 | + |
| 64 | + |
| 65 | + public void serverResponse() { |
| 66 | + Assert.assertEquals(mainControler.getServerResponse("list"), "test\ntest1\ntest2\ntest3\ntest4\ntest5"); |
| 67 | + } |
| 68 | + |
| 69 | + @Test |
| 70 | + public void deleteMemberProduct() { |
| 71 | + Integer idOfFiredMember= mainControler.listAll().size()-1; |
| 72 | + List<? extends IItem> basket = mainControler.getMembersDAO().getMembersAudience().get(idOfFiredMember).getItems(); |
| 73 | + Integer lastBasketSize = basket.size() - 2; |
| 74 | + mainControler.deleteMembersProduct (new Long(idOfFiredMember),0); |
| 75 | + mainControler.deleteMembersProduct (new Long(idOfFiredMember),4); |
| 76 | + Assert.assertEquals(lastBasketSize,new Integer(basket.size())); |
82 | 77 | }
|
83 | 78 |
|
84 | 79 | @Bean
|
85 | 80 | @Primary
|
86 |
| - public IController iController() { |
87 |
| - if (IController==null) { |
88 |
| - IController=mock(Controller.class); |
89 |
| - when(IController.execute("list")).thenReturn("test\ntest\ntest\ntest\ntest\ntest" |
90 |
| - + ""); |
91 |
| - |
| 81 | + public ITelnet TelnetConnector() { |
| 82 | + if (telnetHandler==null) { |
| 83 | + telnetHandler=mock(TelnetConnector.class); |
| 84 | + when(telnetHandler.get("list")).thenReturn("test\ntest1\ntest2\ntest3\ntest4\ntest5"); |
| 85 | + when(telnetHandler.get(startsWith("test"))).thenReturn("mtest\nmtest1\nmtest2\nmtest3\nmtest4\nmtest5"); |
92 | 86 | }
|
93 |
| - |
94 |
| - return IController; |
| 87 | + return telnetHandler; |
95 | 88 | }
|
96 | 89 |
|
97 | 90 | @Bean
|
98 | 91 | @Primary
|
99 | 92 | public MainWindow iMainWindow() {
|
100 |
| - if (IController==null) { |
| 93 | + if (telnetHandler==null) { |
101 | 94 | disableWindow=mock(MainWindow.class);
|
102 | 95 | }
|
103 | 96 |
|
|
0 commit comments