List of usage examples for org.springframework.validation.support BindingAwareModelMap BindingAwareModelMap
BindingAwareModelMap
From source file:org.itstep.java.web.controller.GoodControllerTest.java
/** * Test of all method, of class GoodController. *///from w w w . j a va 2s.c o m @Test public void testAll() { System.out.println("all"); Integer id = 1; Model model = new BindingAwareModelMap(); TestableGoodController instance = new TestableGoodController(); instance.setGoodService(new GoodService() { @Override public List<Good> all() { return new ArrayList<>(); } @Override public List<Good> all(Integer categoryId) { return new ArrayList<>(); } }); String expResult = "all"; String result = instance.all(id, model); assertEquals(expResult, result); // TODO review the generated test code and remove the default call to fail. //fail("The test case is a prototype."); }
From source file:org.itstep.java.web.controller.GoodControllerTest.java
/** * Test of test method, of class GoodController. *//*from w w w . j a v a 2s . c om*/ @Test public void testTest() { System.out.println("test"); BindingAwareModelMap model = new BindingAwareModelMap(); TestableGoodController instance = new TestableGoodController(); instance.setGoodService(new GoodService() { @Override public List<Good> all() { return new ArrayList<>(); } @Override public List<Good> all(Integer categoryId) { return new ArrayList<>(); } }); String expResult = "test"; String result = instance.test(6f, 2f, model); assertEquals(expResult, result); assertEquals(3f, model.get("result")); instance.test(14f, 2f, model); assertEquals(7f, model.get("result")); instance.test(15f, 2f, model); assertEquals(7.5f, model.get("result")); instance.test(15f, 0f, model); assertTrue(Float.isInfinite((Float) model.get("result"))); }
From source file:uk.ac.ebi.emma.controller.GeneManagementDetailControllerTest.java
/** * Test of edit method, of class GeneManagementDetailController. */// www . jav a2 s.co m @Test public void testEditGene() { System.out.println("edit"); int id_gene = 0; String filterGeneKey = "0"; String filterGeneName = "test gene name"; String filterGeneSymbol = "test gene symbol"; String filterChromosome = "test chromosome"; String filterMGIReference = "test mgi reference"; Model model = new BindingAwareModelMap(); GeneManagementDetailController instance = new GeneManagementDetailController(); String expResult = "geneManagementDetail"; String result = instance.edit(id_gene, filterGeneKey, filterGeneName, filterGeneSymbol, filterChromosome, filterMGIReference, model); assertEquals(expResult, result); // Verify function return. Map modelMap = model.asMap(); // Check filter. Filter filter = (Filter) modelMap.get("filter"); assertEquals(filterGeneKey, filter.getGene_key()); assertEquals(filterGeneName, filter.getGeneName()); assertEquals(filterGeneSymbol, filter.getGeneSymbol()); assertEquals(filterChromosome, filter.getChromosome()); assertEquals(filterMGIReference, filter.getGeneMgiReference()); Gene gene = (Gene) modelMap.get("gene"); // The gene's components are null, so there is no more checking that can be done. }
From source file:uk.ac.ebi.emma.controller.GeneManagementListControllerTest.java
/** * Test of go method, of class GeneManagementListController. *//*from w w w . j av a2s .com*/ @Test public void testGo() { System.out.println("go"); String gene_key = "123"; String geneName = "test gene name"; String geneSymbol = "test gene symbol"; String chromosome = "test chromosome"; String mgiReference = "test mgi reference"; Model model = new BindingAwareModelMap(); GeneManagementListController instance = new GeneManagementListController(); String expResult = "geneManagementList"; String result = instance.go(gene_key, geneName, geneSymbol, chromosome, mgiReference, model); assertEquals(expResult, result); Map modelMap = model.asMap(); // Check filter. Filter filter = (Filter) modelMap.get("filter"); assertEquals(gene_key, filter.getGene_key()); assertEquals(geneName, filter.getGeneName()); assertEquals(geneSymbol, filter.getGeneSymbol()); assertEquals(chromosome, filter.getChromosome()); assertEquals(mgiReference, filter.getGeneMgiReference()); // Check filteredGenesList. List<Gene> filteredGenesList = (List<Gene>) modelMap.get("filteredGenesList"); assertTrue(filteredGenesList.size() >= 0); // Check showResultsForm. boolean showResultsForm = (boolean) modelMap.get("showResultsForm"); assertTrue(showResultsForm); // Check resultsCount. int resultsCount = (int) modelMap.get("resultsCount"); assertEquals(filteredGenesList.size(), resultsCount); }
From source file:com.comcast.video.dawg.controller.park.PopulateControllerTest.java
@SuppressWarnings("unchecked") @Test//from www . ja v a 2 s . c o m public void testPopulateWithModel() { PopulateController controller = new PopulateController(); ParkService mockParkService = new MockParkService(); ChimpsToken myToken = new ChimpsToken("mytoken"); mockParkService.saveToken(myToken); ReflectionTestUtils.setField(controller, "parkService", mockParkService); Model model = new BindingAwareModelMap(); Assert.assertEquals(controller.populate(model), "populate"); List<ChimpsToken> tokens = (List<ChimpsToken>) model.asMap().get("population"); Assert.assertNotNull(tokens); Assert.assertTrue(tokens.contains(myToken)); }
From source file:com.comcast.video.dawg.controller.park.PopulateControllerTest.java
@Test public void testPopulateTable() { PopulateController controller = new PopulateController(); ParkService mockParkService = new MockParkService(); ReflectionTestUtils.setField(controller, "parkService", mockParkService); Model model = new BindingAwareModelMap(); Assert.assertEquals(controller.populateTable(model), "populateTable"); Assert.assertNotNull(model.asMap().get("population")); }
From source file:uk.ac.ebi.emma.controller.GeneManagementListControllerTest.java
/** * Test of showFilter method, of class GeneManagementListController. *//*from ww w.ja v a2 s . c o m*/ @Test public void testShowFilter() { System.out.println("showFilter"); String gene_key = "123"; String geneName = "test gene name"; String geneSymbol = "test gene symbol"; String chromosome = "test chromosome"; String mgiReference = "test mgi reference"; Model model = new BindingAwareModelMap(); GeneManagementListController instance = new GeneManagementListController(); String expResult = "geneManagementList"; String result = instance.showFilter(gene_key, geneName, geneSymbol, chromosome, mgiReference, model); assertEquals(expResult, result); Map modelMap = model.asMap(); // Check filter. Filter filter = (Filter) modelMap.get("filter"); assertEquals(gene_key, filter.getGene_key()); assertEquals(geneName, filter.getGeneName()); assertEquals(geneSymbol, filter.getGeneSymbol()); assertEquals(chromosome, filter.getChromosome()); assertEquals(mgiReference, filter.getGeneMgiReference()); // Check showResultsForm. boolean showResultsForm = (boolean) modelMap.get("showResultsForm"); assertFalse(showResultsForm); }
From source file:com.comcast.video.dawg.controller.park.ParkControllerTest.java
@SuppressWarnings("unchecked") @Test(dataProvider = "testUserFrontWithValidTokenData") public void testUserFrontWithValidToken(String token, String tag, String q, String[] sort, String[] otherTagsExp) {/*from w ww . j av a 2 s . c o m*/ ParkController controller = new ParkController(); Map<String, Object>[] filteredStbs = new HashMap[1]; Map<String, Object>[] allStbs = new HashMap[2]; Map<String, Object> stb1 = new HashMap<String, Object>(); stb1.put(MetaStb.ID, "sample"); stb1.put(MetaStb.TAGS, Arrays.asList("tag1")); stb1.put(MetaStb.MACADDRESS, "00:00:00:00:00"); Map<String, Object> stb2 = new HashMap<String, Object>(); stb2.put(MetaStb.ID, "otherDevice"); stb2.put(MetaStb.TAGS, Arrays.asList("tag2", "tag3")); stb2.put(MetaStb.MACADDRESS, "00:00:00:00:01"); filteredStbs[0] = stb1; allStbs[0] = stb1; allStbs[1] = stb2; ReflectionTestUtils.setField(controller, "serverUtils", utils); ParkService mockService = EasyMock.createMock(ParkService.class); if (q == null) { EasyMock.expect(mockService.findAll((Pageable) EasyMock.anyObject())).andReturn(allStbs); } else { EasyMock.expect( mockService.findByKeys((String[]) EasyMock.anyObject(), (Pageable) EasyMock.anyObject())) .andReturn(filteredStbs); EasyMock.expect(mockService.findAll()).andReturn(allStbs); } if (tag != null) { EasyMock.expect( mockService.findByCriteria((Criteria) EasyMock.anyObject(), (Pageable) EasyMock.anyObject())) .andReturn(filteredStbs); } EasyMock.replay(mockService); ReflectionTestUtils.setField(controller, "service", mockService); ReflectionTestUtils.setField(controller, "config", createConfig()); Integer page = Integer.valueOf(1); Integer size = Integer.valueOf(1); Boolean asc = Boolean.TRUE; try { Model model = new BindingAwareModelMap(); MockHttpSession session = new MockHttpSession(); Assert.assertEquals("index", controller.userFront(token, tag, q, page, size, asc, sort, model, session)); Assert.assertEquals(model.asMap().get("search"), q == null ? "" : q); String otherTagsJson = (String) model.asMap().get("otherTags"); String deviceTagsJson = (String) model.asMap().get("deviceTags"); JsonCerealEngine engine = new JsonCerealEngine(); List<String> otherTags = engine.readFromString(otherTagsJson, List.class); Map<String, List<String>> deviceTags = engine.readFromString(deviceTagsJson, Map.class); Assert.assertEquals(otherTags.size(), otherTagsExp.length); for (String tags : otherTagsExp) { Assert.assertTrue(otherTags.contains(tags)); } Assert.assertEquals(deviceTags.size(), q != null ? 1 : 2); Assert.assertTrue(deviceTags.containsKey("sample")); Assert.assertTrue(deviceTags.get("sample").contains("tag1")); } catch (CerealException e) { Assert.fail(e.getMessage()); } }
From source file:alfio.controller.ReservationFlowIntegrationTest.java
/** * Test a complete offline payment flow. * Will not check in detail...//from w w w. j a v a 2s . com */ @Test public void reservationFlowTest() throws Exception { String eventName = event.getShortName(); assertTrue(checkInManager.findAllFullTicketInfo(event.getId()).isEmpty()); List<EventStatistic> eventStatistic = eventStatisticsManager.getAllEventsWithStatistics(user); assertEquals(1, eventStatistic.size()); assertTrue(eventStatisticsManager .getTicketSoldStatistics(event.getId(), new Date(0), DateUtils.addDays(new Date(), 1)).isEmpty()); EventWithAdditionalInfo eventWithAdditionalInfo = eventStatisticsManager .getEventWithAdditionalInfo(event.getShortName(), user); assertEquals(0, eventWithAdditionalInfo.getNotSoldTickets()); assertEquals(0, eventWithAdditionalInfo.getSoldTickets()); assertEquals(20, eventWithAdditionalInfo.getAvailableSeats()); eventManager.toggleActiveFlag(event.getId(), user, true); // list events String eventList = eventController.listEvents(new BindingAwareModelMap(), Locale.ENGLISH); if (eventManager.getPublishedEvents().size() == 1) { Assert.assertTrue(eventList.startsWith("redirect:/")); } else { assertEquals("/event/event-list", eventList); } // // show event String showEvent = eventController.showEvent(eventName, new BindingAwareModelMap(), new MockHttpServletRequest(), Locale.ENGLISH); assertEquals("/event/show-event", showEvent); // // check calendar checkCalendar(eventName); // String redirectResult = reserveTicket(eventName); String redirectStart = "redirect:/event/" + eventName + "/reservation/"; // check reservation success Assert.assertTrue(redirectResult.startsWith(redirectStart)); Assert.assertTrue(redirectResult.endsWith("/book")); // String reservationIdentifier = redirectResult.substring(redirectStart.length()).replace("/book", ""); // check that the payment page is shown String reservationPage = reservationController.showPaymentPage(eventName, reservationIdentifier, null, null, null, null, null, null, null, null, null, null, null, new BindingAwareModelMap(), Locale.ENGLISH); assertEquals("/event/reservation-page", reservationPage); // // pay offline String successPage = payOffline(eventName, reservationIdentifier); assertEquals("redirect:/event/" + eventName + "/reservation/" + reservationIdentifier + "/success", successPage); // //go to success page, payment is still pending String confirmationPage = reservationController.showConfirmationPage(eventName, reservationIdentifier, false, false, new BindingAwareModelMap(), Locale.ENGLISH, new MockHttpServletRequest()); Assert.assertTrue(confirmationPage.endsWith("/waitingPayment")); assertEquals("/event/reservation-waiting-for-payment", reservationController.showWaitingPaymentPage( eventName, reservationIdentifier, new BindingAwareModelMap(), Locale.ENGLISH)); // validatePayment(eventName, reservationIdentifier); // Assert.assertTrue(reservationController.showWaitingPaymentPage(eventName, reservationIdentifier, new BindingAwareModelMap(), Locale.ENGLISH).endsWith("/success")); // TicketDecorator ticketDecorator = checkReservationComplete(eventName, reservationIdentifier); // String ticketIdentifier = ticketDecorator.getUuid(); //ticket is still not assigned, will redirect Assert.assertTrue(ticketController .showTicket(eventName, ticketIdentifier, false, Locale.ENGLISH, new BindingAwareModelMap()) .startsWith("redirect:/event/")); Assert.assertTrue(ticketController .showTicketForUpdate(eventName, ticketIdentifier, new BindingAwareModelMap(), Locale.ENGLISH) .startsWith("redirect:/event/")); // String fname1 = "Test"; String lname1 = "McTest"; //assign ticket to person assignTicket(eventName, reservationIdentifier, ticketIdentifier, fname1, lname1); assertEquals(1, checkInManager.findAllFullTicketInfo(event.getId()).size()); assertEquals("/event/update-ticket", ticketController.showTicketForUpdate(eventName, ticketIdentifier, new BindingAwareModelMap(), Locale.ENGLISH)); // assertEquals("/event/show-ticket", ticketController.showTicket(eventName, ticketIdentifier, false, Locale.ENGLISH, new BindingAwareModelMap())); // checkCSV(eventName, ticketIdentifier, fname1 + " " + lname1); // use api to update UpdateTicketOwnerForm updateTicketOwnerForm = new UpdateTicketOwnerForm(); updateTicketOwnerForm.setFirstName("Test"); updateTicketOwnerForm.setLastName("Testson"); updateTicketOwnerForm.setEmail("testmctest@test.com"); updateTicketOwnerForm.setUserLanguage("en"); reservationApiController.assignTicketToPerson(eventName, ticketIdentifier, true, updateTicketOwnerForm, new BeanPropertyBindingResult(updateTicketOwnerForm, "updateTicketForm"), new MockHttpServletRequest(), new BindingAwareModelMap(), null); checkCSV(eventName, ticketIdentifier, "Test Testson"); // //update String fname2 = "Test"; String lname2 = "OTest"; assignTicket(eventName, reservationIdentifier, ticketIdentifier, fname2, lname2); checkCSV(eventName, ticketIdentifier, fname2 + " " + lname2); //lock ticket Principal principal = Mockito.mock(Principal.class); Mockito.when(principal.getName()).thenReturn(user); eventApiController.toggleTicketLocking(eventName, ticketDecorator.getCategoryId(), ticketDecorator.getId(), principal); assignTicket(eventName, reservationIdentifier, ticketIdentifier, fname1, fname2); checkCSV(eventName, ticketIdentifier, fname2 + " " + lname2); //ticket has changed, update ticketDecorator = checkReservationComplete(eventName, reservationIdentifier); // check stats after selling one ticket assertFalse(eventStatisticsManager .getTicketSoldStatistics(event.getId(), new Date(0), DateUtils.addDays(new Date(), 2)).isEmpty()); EventWithAdditionalInfo eventWithAdditionalInfo2 = eventStatisticsManager .getEventWithAdditionalInfo(event.getShortName(), user); assertEquals(0, eventWithAdditionalInfo2.getNotSoldTickets()); assertEquals(1, eventWithAdditionalInfo2.getSoldTickets()); assertEquals(20, eventWithAdditionalInfo2.getAvailableSeats()); assertEquals(0, eventWithAdditionalInfo2.getCheckedInTickets()); //--- check in sequence String ticketCode = ticketDecorator.ticketCode(event.getPrivateKey()); TicketAndCheckInResult ticketAndCheckInResult = checkInApiController.findTicketWithUUID(event.getId(), ticketIdentifier, ticketCode); assertEquals(CheckInStatus.OK_READY_TO_BE_CHECKED_IN, ticketAndCheckInResult.getResult().getStatus()); CheckInApiController.TicketCode tc = new CheckInApiController.TicketCode(); tc.setCode(ticketCode); assertEquals(CheckInStatus.SUCCESS, checkInApiController .checkIn(event.getId(), ticketIdentifier, tc, new TestingAuthenticationToken("ciccio", "ciccio")) .getResult().getStatus()); List<ScanAudit> audits = scanAuditRepository.findAllForEvent(event.getId()); assertFalse(audits.isEmpty()); assertTrue(audits.stream().anyMatch(sa -> sa.getTicketUuid().equals(ticketIdentifier))); TicketAndCheckInResult ticketAndCheckInResultOk = checkInApiController.findTicketWithUUID(event.getId(), ticketIdentifier, ticketCode); assertEquals(CheckInStatus.ALREADY_CHECK_IN, ticketAndCheckInResultOk.getResult().getStatus()); // check stats after check in one ticket assertFalse(eventStatisticsManager .getTicketSoldStatistics(event.getId(), new Date(0), DateUtils.addDays(new Date(), 1)).isEmpty()); EventWithAdditionalInfo eventWithAdditionalInfo3 = eventStatisticsManager .getEventWithAdditionalInfo(event.getShortName(), user); assertEquals(0, eventWithAdditionalInfo3.getNotSoldTickets()); assertEquals(0, eventWithAdditionalInfo3.getSoldTickets()); assertEquals(20, eventWithAdditionalInfo3.getAvailableSeats()); assertEquals(1, eventWithAdditionalInfo3.getCheckedInTickets()); //test revert check in assertTrue(checkInApiController.revertCheckIn(event.getId(), ticketIdentifier, principal)); assertFalse(checkInApiController.revertCheckIn(event.getId(), ticketIdentifier, principal)); TicketAndCheckInResult ticketAndCheckInResult2 = checkInApiController.findTicketWithUUID(event.getId(), ticketIdentifier, ticketCode); assertEquals(CheckInStatus.OK_READY_TO_BE_CHECKED_IN, ticketAndCheckInResult2.getResult().getStatus()); UsersApiController.UserWithPasswordAndQRCode sponsorUser = usersApiController .insertUser(new UserModification(null, event.getOrganizationId(), "SPONSOR", "sponsor", "first", "last", "email@email.com"), "http://localhost:8080", principal); Principal sponsorPrincipal = Mockito.mock(Principal.class); Mockito.when(sponsorPrincipal.getName()).thenReturn(sponsorUser.getUsername()); // check failures assertEquals(CheckInStatus.EVENT_NOT_FOUND, attendeeApiController.scanBadge( new AttendeeApiController.SponsorScanRequest("not-existing-event", "not-existing-ticket"), sponsorPrincipal).getBody().getResult().getStatus()); assertEquals(CheckInStatus.TICKET_NOT_FOUND, attendeeApiController .scanBadge(new AttendeeApiController.SponsorScanRequest(eventName, "not-existing-ticket"), sponsorPrincipal) .getBody().getResult().getStatus()); assertEquals(CheckInStatus.INVALID_TICKET_STATE, attendeeApiController .scanBadge(new AttendeeApiController.SponsorScanRequest(eventName, ticketIdentifier), sponsorPrincipal) .getBody().getResult().getStatus()); // // check stats after revert check in one ticket assertFalse(eventStatisticsManager .getTicketSoldStatistics(event.getId(), new Date(0), DateUtils.addDays(new Date(), 1)).isEmpty()); EventWithAdditionalInfo eventWithAdditionalInfo4 = eventStatisticsManager .getEventWithAdditionalInfo(event.getShortName(), user); assertEquals(0, eventWithAdditionalInfo4.getNotSoldTickets()); assertEquals(1, eventWithAdditionalInfo4.getSoldTickets()); assertEquals(20, eventWithAdditionalInfo4.getAvailableSeats()); assertEquals(0, eventWithAdditionalInfo4.getCheckedInTickets()); CheckInApiController.TicketCode tc2 = new CheckInApiController.TicketCode(); tc2.setCode(ticketCode); TicketAndCheckInResult ticketAndcheckInResult = checkInApiController.checkIn(event.getId(), ticketIdentifier, tc2, new TestingAuthenticationToken("ciccio", "ciccio")); assertEquals(CheckInStatus.SUCCESS, ticketAndcheckInResult.getResult().getStatus()); // // List<Integer> offlineIdentifiers = checkInApiController.getOfflineIdentifiers(event.getShortName(), 0L, new MockHttpServletResponse(), principal); assertTrue(offlineIdentifiers.isEmpty()); configurationRepository.insertEventLevel(event.getOrganizationId(), event.getId(), ConfigurationKeys.OFFLINE_CHECKIN_ENABLED.name(), "true", null); configurationRepository.insert(ConfigurationKeys.ALFIO_PI_INTEGRATION_ENABLED.name(), "true", null); offlineIdentifiers = checkInApiController.getOfflineIdentifiers(event.getShortName(), 0L, new MockHttpServletResponse(), principal); assertFalse(offlineIdentifiers.isEmpty()); Map<String, String> payload = checkInApiController.getOfflineEncryptedInfo(event.getShortName(), Collections.emptyList(), offlineIdentifiers, principal); assertEquals(1, payload.size()); Ticket ticket = ticketAndcheckInResult.getTicket(); String ticketKey = ticket.hmacTicketInfo(event.getPrivateKey()); String hashedTicketKey = DigestUtils.sha256Hex(ticketKey); String encJson = payload.get(hashedTicketKey); assertNotNull(encJson); String ticketPayload = CheckInManager.decrypt(ticket.getUuid() + "/" + ticketKey, encJson); Map<String, String> jsonPayload = Json.fromJson(ticketPayload, new TypeReference<Map<String, String>>() { }); assertNotNull(jsonPayload); assertEquals(8, jsonPayload.size()); assertEquals("Test", jsonPayload.get("firstName")); assertEquals("OTest", jsonPayload.get("lastName")); assertEquals("Test OTest", jsonPayload.get("fullName")); assertEquals(ticket.getUuid(), jsonPayload.get("uuid")); assertEquals("testmctest@test.com", jsonPayload.get("email")); assertEquals("CHECKED_IN", jsonPayload.get("status")); String categoryName = ticketCategoryRepository.findByEventId(event.getId()).stream().findFirst() .orElseThrow(IllegalStateException::new).getName(); assertEquals(categoryName, jsonPayload.get("category")); // // check register sponsor scan success flow assertTrue(attendeeApiController.getScannedBadges(event.getShortName(), EventUtil.JSON_DATETIME_FORMATTER.format(LocalDateTime.of(1970, 1, 1, 0, 0)), sponsorPrincipal) .getBody().isEmpty()); assertEquals(CheckInStatus.SUCCESS, attendeeApiController .scanBadge(new AttendeeApiController.SponsorScanRequest(eventName, ticket.getUuid()), sponsorPrincipal) .getBody().getResult().getStatus()); assertEquals(1, attendeeApiController.getScannedBadges(event.getShortName(), EventUtil.JSON_DATETIME_FORMATTER.format(LocalDateTime.of(1970, 1, 1, 0, 0)), sponsorPrincipal).getBody().size()); // eventManager.deleteEvent(event.getId(), principal.getName()); }