public static void main(String[] args) { ZonedDateTime apollo11launch = ZonedDateTime.of(1969, 7, 16, 9, 32, 0, 0, ZoneId.of("America/New_York")); String formatted = DateTimeFormatter.ISO_DATE_TIME.format(apollo11launch); // 1969-07-16T09:32:00-05:00[America/New_York] System.out.println(formatted); DateTimeFormatter formatter = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.LONG); formatted = formatter.format(apollo11launch); // July 16, 1969 9:32:00 AM EDT System.out.println(formatted); formatted = formatter.withLocale(Locale.FRENCH).format(apollo11launch); // 16 juillet 1969 09:32:00 EDT System.out.println(formatted); formatter = DateTimeFormatter.ofPattern("E yyyy-MM-dd HH:mm"); formatted = formatter.format(apollo11launch); System.out.println(formatted); LocalDate churchsBirthday = LocalDate.parse("1903-06-14"); System.out.println("churchsBirthday: " + churchsBirthday); apollo11launch = ZonedDateTime.parse( "1969-07-16 03:32:00-0400", DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ssxx")); System.out.println("apollo11launch: " + apollo11launch); }
private FilterBuilder[] makeFilters(ZonedDateTime currentDate) { List<FilterBuilder> builders = new ArrayList<>(); boolean minRange = down(TimeUnit.HOURS, currentDate).isBefore(config.getFrom()); boolean maxRange = up(TimeUnit.HOURS, currentDate).isAfter(config.getTo()); if (minRange || maxRange) { RangeFilterBuilder rangeFilterBuilder = FilterBuilders.rangeFilter("received_at"); if (minRange) rangeFilterBuilder = rangeFilterBuilder.gte(DATE_FORMAT.format(config.getFrom())); if (maxRange) rangeFilterBuilder = rangeFilterBuilder.lte(DATE_FORMAT.format(config.getTo())); builders.add(rangeFilterBuilder); } return builders.toArray(new FilterBuilder[builders.size()]); }
@Override public boolean handleMessage(final Message event) { final String message = event.getValue().toLowerCase(); final Channel channel = event.getChannel(); if (message.startsWith("info ")) { final String key = message.substring("info ".length()); final Factoid factoid = dao.getFactoid(key); if (factoid != null) { DateTimeFormatter formatter = DateTimeFormatter.ofPattern(INFO_DATE_FORMAT); LocalDateTime updated = factoid.getUpdated(); String formatted = formatter.format(updated); getBot() .postMessageToChannel( event, Sofia.factoidInfo( key, factoid.getLocked() ? "*" : "", factoid.getUserName(), formatted, factoid.getValue())); } else { getBot().postMessageToChannel(event, Sofia.factoidUnknown(key)); } return true; } return false; }
/** Renders this TransferFile as wikitext for Commons. */ private String gen() { String t = sumSection + licSection; t = t.replaceAll("(?s)\\<!\\-\\-.*?\\-\\-\\>", ""); // strip comments t = t.replaceAll("(?i)\\n?\\[\\[(Category:).*?\\]\\]", ""); // categories don't transfer well. t = t.replaceAll("(?<=\\[\\[)(.+?\\]\\])", "w:$1"); // add enwp prefix to links t = t.replaceAll("(?i)\\[\\[(w::|w:w:)", "[[w:"); // Remove any double colons in interwiki links // Generate Upload Log Section t += "\n== {{Original upload log}} ==\n" + String.format( "{{Original description page|en.wikipedia|%s}}%n", FString.enc(enwp.nss(wpFN))) + "{| class=\"wikitable\"\n! {{int:filehist-datetime}} !! {{int:filehist-dimensions}} !! {{int:filehist-user}} " + "!! {{int:filehist-comment}}\n|-\n"; for (ImageInfo ii : imgInfoL) t += String.format( uLFmt, dtf.format(LocalDateTime.ofInstant(ii.timestamp, ZoneOffset.UTC)), ii.dimensions.x, ii.dimensions.y, ii.user, ii.user, ii.summary.replace("\n", " ")); t += "|}\n\n{{Subst:Unc}}"; if (mtc.useTrackingCat) t += "\n[[Category:Uploaded with MTC!]]"; return t; }
public Optional<String> toImageBlock(Image image) { if (!current.currentPath().isPresent()) asciiDocController.saveDoc(); Path currentPath = current.currentPath().map(Path::getParent).get(); IOHelper.createDirectories(currentPath.resolve("images")); List<String> buffer = new LinkedList<>(); DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(asciiDocController.getClipboardImageFilePattern()); Path path = Paths.get(dateTimeFormatter.format(LocalDateTime.now())); Path targetImage = currentPath.resolve("images").resolve(path.getFileName()); try { BufferedImage fromFXImage = SwingFXUtils.fromFXImage(image, null); ImageIO.write(fromFXImage, "png", targetImage.toFile()); } catch (Exception e) { logger.error("Problem occured while saving clipboard image {}", targetImage); } buffer.add(String.format("image::images/%s[]", path.getFileName())); if (buffer.size() > 0) return Optional.of(String.join("\n", buffer)); return Optional.empty(); }
public void setDateTime(LocalDate date) { try { super.remove(0, getLength()); final String dateText = dateFormatter.format(date); super.insertString(0, dateText, null); } catch (BadLocationException e) { LOGGER.log(Level.SEVERE, e.getLocalizedMessage(), e); } }
private void isoDate() { // 建格式器 DateTimeFormatter d = DateTimeFormatter.ISO_DATE; // 创建对象 LocalDate ld = LocalDate.now(); System.out.println(ld); String str = d.format(ld); System.out.println(str); }
public static void main(String[] args) { LocalDate jetzt = LocalDate.now(); DateTimeFormatter myformatter = DateTimeFormatter.ofPattern("EEEE, d. MMM yyyy"); System.out.println("Heute ist " + myformatter.format(jetzt) + "."); System.out.println("ein weiteres Bespiel....."); java.util.Random r = new java.util.Random(); int x = r.nextInt(1000); System.out.println("eine Zufallszahl: " + x); }
@Override protected String toString(LocalDateTime value) { DateTimeFormatter formatter = getDateTimeFormatter(); if (formatter != null) { try { return formatter.format(value); } catch (Exception e) { CommonUtils.ignoreException(e); } } return super.toString(value); }
static void f3() { DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd-HH:mm:ss"); LocalDateTime dateTime = LocalDateTime.now(); String string = formatter.format(dateTime); System.out.println(string); DateTimeFormatter formatter1 = DateTimeFormatter.ofPattern("yyyyMMdd-HH:mm:ss"); LocalDateTime dateTime1 = LocalDateTime.parse("20160124-15:03:59", formatter1); System.out.println(dateTime1); // LocalDateTime dt1 = LocalDateTime.of(2016, Month.JANUARY, 10, 20, 30); // LocalDateTime dt2 = LocalDateTime.of(date, time); // LocalDateTime dt3 = date.atTime(20, 30); // LocalDateTime dt4 = date.atTime(time); }
@SubscribeMapping("/topic/activity") @SendTo("/topic/tracker") public ActivityDTO sendActivity( @Payload ActivityDTO activityDTO, StompHeaderAccessor stompHeaderAccessor, Principal principal) { activityDTO.setUserLogin(SecurityUtils.getCurrentUserLogin()); activityDTO.setUserLogin(principal.getName()); activityDTO.setSessionId(stompHeaderAccessor.getSessionId()); activityDTO.setIpAddress(stompHeaderAccessor.getSessionAttributes().get(IP_ADDRESS).toString()); Instant instant = Instant.ofEpochMilli(Calendar.getInstance().getTimeInMillis()); activityDTO.setTime( dateTimeFormatter.format(ZonedDateTime.ofInstant(instant, ZoneOffset.systemDefault()))); log.debug("Sending user tracking data {}", activityDTO); return activityDTO; }
/** @see javax.swing.table.TableModel#getValueAt(int, int) */ @Override public Object getValueAt(final int rowIndex, final int columnIndex) { switch (columnIndex) { case 0: if (reminders.get(rowIndex).isApproved()) { return enabledSymbol; } return null; case 1: return reminders.get(rowIndex).getReminder().getDescription(); case 2: return formatter.format(reminders.get(rowIndex).getCommitDate()); default: return null; } }
private List<SearchRequestBuilder> makeRequestBuilders() { List<SearchRequestBuilder> builders = new ArrayList<>(); ZonedDateTime currentDate = config.getFrom(); ZonedDateTime maxDate = up(TimeUnit.HOURS, config.getTo()); do { builders.add( client .prepareSearch( appendForEach(INDEXES_PREFIXES, ELASTIC_INDEX_DATE_FORMAT.format(currentDate))) .setTypes(TYPES) .setSize(config.getBucketSize()) .setPostFilter(FilterBuilders.andFilter(makeFilters(currentDate)))); currentDate = currentDate.plusDays(1); } while (currentDate.isBefore(maxDate)); return builders; }
public void add(TempReading temp) { qTemp.add(temp); if (fileWrite) { StringBuilder sb = new StringBuilder(); // build string with temp and date; sb.append(decForm.format(temp.getTemp())) .append(dateParser.format(temp.getTempTime())) .append("\n"); // write it to the file try (BufferedWriter tOut = new BufferedWriter(new FileWriter(this.fileName, true))) { tOut.write(sb.toString()); } catch (IOException e) { log.warn("Error on Outside Temperature fileName", e); } } }
@Override public Session toManagementSession() { SessionBuilder builder = new SessionBuilder(); builder.setSessionId(getSessionId()); IpAddress address; InetAddress address1 = InetAddresses.forString(header.getAddress()); if (address1 instanceof Inet4Address) { address = new IpAddress(new Ipv4Address(header.getAddress())); } else { address = new IpAddress(new Ipv6Address(header.getAddress())); } builder.setSourceHost(new Host(address)); Preconditions.checkState(DateAndTime.PATTERN_CONSTANTS.size() == 1); String formattedDateTime = dateFormatter.format(loginTime); Matcher matcher = dateTimePattern.matcher(formattedDateTime); Preconditions.checkState( matcher.matches(), "Formatted datetime %s does not match pattern %s", formattedDateTime, dateTimePattern); builder.setLoginTime(new DateAndTime(formattedDateTime)); builder.setInBadRpcs(new ZeroBasedCounter32(inRpcFail)); builder.setInRpcs(new ZeroBasedCounter32(inRpcSuccess)); builder.setOutRpcErrors(new ZeroBasedCounter32(outRpcError)); builder.setUsername(header.getUserName()); builder.setTransport(getTransportForString(header.getTransport())); builder.setOutNotifications(new ZeroBasedCounter32(outNotification)); builder.setKey(new SessionKey(getSessionId())); Session1Builder builder1 = new Session1Builder(); builder1.setSessionIdentifier(header.getSessionIdentifier()); builder.addAugmentation(Session1.class, builder1.build()); return builder.build(); }
@Override public void logged(LogEntry entry) { try { // try to get a writer Writer writer = getWriter(); if (writer == null) { // silently fail, ELK service might just not be running return; } // prepare a exception string if the log contains an exception String exception = entry.getException() == null ? "" : " " + entry.getException().getMessage(); // format time of log Instant dateTimeInstant = new Date(entry.getTime()).toInstant(); LocalDateTime dateTime = LocalDateTime.ofInstant(dateTimeInstant, ZoneId.of("GMT")); // concatenate log string String log = m_formatter.format(dateTime) + " " + m_hostname + " " + m_frameworkUUID + " " + entry.getBundle().getSymbolicName() + " " + getLogLevel(entry.getLevel()) + " " + entry.getMessage() + exception; // write log string to logstash writer.write(log + "\n"); writer.flush(); } catch (Exception e) { // silently fail, ELK service might just not be running cleanup(); } }
/** * Returns the given date as a well formatted String. The above defined {@link * DateUtil#DATE_PATTERN} is used. * * @param date the date to be returned as a string * @return formatted string */ public static String format(LocalDate date) { if (date == null) { return null; } return DATE_FORMATTER.format(date); }
@JsonGetter public String getFormattedTokenDate() { return DATE_TIME_FORMATTER.format(this.tokenDate); }
public static String formatDataDir(LogFilePrefix prefix) { return CREATE_TIME_FORMATTER.format(prefix.getCreatedAt()); }
@Override public void serialize( TemporalAccessor value, JsonGenerator generator, SerializerProvider serializerProvider) throws IOException { generator.writeString(ISOFormatter.format(value)); }
/** * Test class for the OperationResource REST controller. * * @see OperationResource */ @RunWith(SpringRunner.class) @SpringBootTest(classes = JhipsterElasticsearchSampleApplicationApp.class) public class OperationResourceIntTest { private static final DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'").withZone(ZoneId.of("Z")); private static final ZonedDateTime DEFAULT_DATE = ZonedDateTime.ofInstant(Instant.ofEpochMilli(0L), ZoneId.systemDefault()); private static final ZonedDateTime UPDATED_DATE = ZonedDateTime.now(ZoneId.systemDefault()).withNano(0); private static final String DEFAULT_DATE_STR = dateTimeFormatter.format(DEFAULT_DATE); private static final String DEFAULT_DESCRIPTION = "AAAAA"; private static final String UPDATED_DESCRIPTION = "BBBBB"; private static final BigDecimal DEFAULT_AMOUNT = new BigDecimal(1); private static final BigDecimal UPDATED_AMOUNT = new BigDecimal(2); @Inject private OperationRepository operationRepository; @Inject private OperationSearchRepository operationSearchRepository; @Inject private MappingJackson2HttpMessageConverter jacksonMessageConverter; @Inject private PageableHandlerMethodArgumentResolver pageableArgumentResolver; @Inject private EntityManager em; private MockMvc restOperationMockMvc; private Operation operation; @PostConstruct public void setup() { MockitoAnnotations.initMocks(this); OperationResource operationResource = new OperationResource(); ReflectionTestUtils.setField( operationResource, "operationSearchRepository", operationSearchRepository); ReflectionTestUtils.setField(operationResource, "operationRepository", operationRepository); this.restOperationMockMvc = MockMvcBuilders.standaloneSetup(operationResource) .setCustomArgumentResolvers(pageableArgumentResolver) .setMessageConverters(jacksonMessageConverter) .build(); } /** * Create an entity for this test. * * <p>This is a static method, as tests for other entities might also need it, if they test an * entity which requires the current entity. */ public static Operation createEntity(EntityManager em) { Operation operation = new Operation(); operation.setDate(DEFAULT_DATE); operation.setDescription(DEFAULT_DESCRIPTION); operation.setAmount(DEFAULT_AMOUNT); return operation; } @Before public void initTest() { operationSearchRepository.deleteAll(); operation = createEntity(em); } @Test @Transactional public void createOperation() throws Exception { int databaseSizeBeforeCreate = operationRepository.findAll().size(); // Create the Operation restOperationMockMvc .perform( post("/api/operations") .contentType(TestUtil.APPLICATION_JSON_UTF8) .content(TestUtil.convertObjectToJsonBytes(operation))) .andExpect(status().isCreated()); // Validate the Operation in the database List<Operation> operations = operationRepository.findAll(); assertThat(operations).hasSize(databaseSizeBeforeCreate + 1); Operation testOperation = operations.get(operations.size() - 1); assertThat(testOperation.getDate()).isEqualTo(DEFAULT_DATE); assertThat(testOperation.getDescription()).isEqualTo(DEFAULT_DESCRIPTION); assertThat(testOperation.getAmount()).isEqualTo(DEFAULT_AMOUNT); // Validate the Operation in ElasticSearch Operation operationEs = operationSearchRepository.findOne(testOperation.getId()); assertThat(operationEs).isEqualToComparingFieldByField(testOperation); } @Test @Transactional public void checkDateIsRequired() throws Exception { int databaseSizeBeforeTest = operationRepository.findAll().size(); // set the field null operation.setDate(null); // Create the Operation, which fails. restOperationMockMvc .perform( post("/api/operations") .contentType(TestUtil.APPLICATION_JSON_UTF8) .content(TestUtil.convertObjectToJsonBytes(operation))) .andExpect(status().isBadRequest()); List<Operation> operations = operationRepository.findAll(); assertThat(operations).hasSize(databaseSizeBeforeTest); } @Test @Transactional public void checkAmountIsRequired() throws Exception { int databaseSizeBeforeTest = operationRepository.findAll().size(); // set the field null operation.setAmount(null); // Create the Operation, which fails. restOperationMockMvc .perform( post("/api/operations") .contentType(TestUtil.APPLICATION_JSON_UTF8) .content(TestUtil.convertObjectToJsonBytes(operation))) .andExpect(status().isBadRequest()); List<Operation> operations = operationRepository.findAll(); assertThat(operations).hasSize(databaseSizeBeforeTest); } @Test @Transactional public void getAllOperations() throws Exception { // Initialize the database operationRepository.saveAndFlush(operation); // Get all the operations restOperationMockMvc .perform(get("/api/operations?sort=id,desc")) .andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) .andExpect(jsonPath("$.[*].id").value(hasItem(operation.getId().intValue()))) .andExpect(jsonPath("$.[*].date").value(hasItem(DEFAULT_DATE_STR))) .andExpect(jsonPath("$.[*].description").value(hasItem(DEFAULT_DESCRIPTION.toString()))) .andExpect(jsonPath("$.[*].amount").value(hasItem(DEFAULT_AMOUNT.intValue()))); } @Test @Transactional public void getOperation() throws Exception { // Initialize the database operationRepository.saveAndFlush(operation); // Get the operation restOperationMockMvc .perform(get("/api/operations/{id}", operation.getId())) .andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) .andExpect(jsonPath("$.id").value(operation.getId().intValue())) .andExpect(jsonPath("$.date").value(DEFAULT_DATE_STR)) .andExpect(jsonPath("$.description").value(DEFAULT_DESCRIPTION.toString())) .andExpect(jsonPath("$.amount").value(DEFAULT_AMOUNT.intValue())); } @Test @Transactional public void getNonExistingOperation() throws Exception { // Get the operation restOperationMockMvc .perform(get("/api/operations/{id}", Long.MAX_VALUE)) .andExpect(status().isNotFound()); } @Test @Transactional public void updateOperation() throws Exception { // Initialize the database operationRepository.saveAndFlush(operation); operationSearchRepository.save(operation); int databaseSizeBeforeUpdate = operationRepository.findAll().size(); // Update the operation Operation updatedOperation = operationRepository.findOne(operation.getId()); updatedOperation.setDate(UPDATED_DATE); updatedOperation.setDescription(UPDATED_DESCRIPTION); updatedOperation.setAmount(UPDATED_AMOUNT); restOperationMockMvc .perform( put("/api/operations") .contentType(TestUtil.APPLICATION_JSON_UTF8) .content(TestUtil.convertObjectToJsonBytes(updatedOperation))) .andExpect(status().isOk()); // Validate the Operation in the database List<Operation> operations = operationRepository.findAll(); assertThat(operations).hasSize(databaseSizeBeforeUpdate); Operation testOperation = operations.get(operations.size() - 1); assertThat(testOperation.getDate()).isEqualTo(UPDATED_DATE); assertThat(testOperation.getDescription()).isEqualTo(UPDATED_DESCRIPTION); assertThat(testOperation.getAmount()).isEqualTo(UPDATED_AMOUNT); // Validate the Operation in ElasticSearch Operation operationEs = operationSearchRepository.findOne(testOperation.getId()); assertThat(operationEs).isEqualToComparingFieldByField(testOperation); } @Test @Transactional public void deleteOperation() throws Exception { // Initialize the database operationRepository.saveAndFlush(operation); operationSearchRepository.save(operation); int databaseSizeBeforeDelete = operationRepository.findAll().size(); // Get the operation restOperationMockMvc .perform( delete("/api/operations/{id}", operation.getId()) .accept(TestUtil.APPLICATION_JSON_UTF8)) .andExpect(status().isOk()); // Validate ElasticSearch is empty boolean operationExistsInEs = operationSearchRepository.exists(operation.getId()); assertThat(operationExistsInEs).isFalse(); // Validate the database is empty List<Operation> operations = operationRepository.findAll(); assertThat(operations).hasSize(databaseSizeBeforeDelete - 1); } @Test @Transactional public void searchOperation() throws Exception { // Initialize the database operationRepository.saveAndFlush(operation); operationSearchRepository.save(operation); // Search the operation restOperationMockMvc .perform(get("/api/_search/operations?query=id:" + operation.getId())) .andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) .andExpect(jsonPath("$.[*].id").value(hasItem(operation.getId().intValue()))) .andExpect(jsonPath("$.[*].date").value(hasItem(DEFAULT_DATE_STR))) .andExpect(jsonPath("$.[*].description").value(hasItem(DEFAULT_DESCRIPTION.toString()))) .andExpect(jsonPath("$.[*].amount").value(hasItem(DEFAULT_AMOUNT.intValue()))); } }
private String formatInstant(Instant instant) { ZonedDateTime dateTime = ZonedDateTime.ofInstant(instant, ZoneId.systemDefault()); return DATE_TIME_FORMATTER.format(dateTime); }
@Override public String format(Long value) { if (value == null) return null; return _formatter.format(getFieldValue().with(getTemporalField(), value)); }
/** * Test class for the ApartmentResource REST controller. * * @see ApartmentResource */ @RunWith(SpringJUnit4ClassRunner.class) @SpringApplicationConfiguration(classes = Application.class) @WebAppConfiguration @IntegrationTest public class ApartmentResourceIntTest { private static final DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ISO_OFFSET_DATE_TIME.withZone(ZoneId.of("Z")); private static final Long DEFAULT_APARTMENT_ID = 0L; private static final Long UPDATED_APARTMENT_ID = 1L; private static final ZonedDateTime DEFAULT_CREATED = ZonedDateTime.ofInstant(Instant.ofEpochMilli(0L), ZoneId.systemDefault()); private static final ZonedDateTime UPDATED_CREATED = ZonedDateTime.now(ZoneId.systemDefault()).withNano(0); private static final String DEFAULT_CREATED_STR = dateTimeFormatter.format(DEFAULT_CREATED); private static final ZonedDateTime DEFAULT_UPDATED = ZonedDateTime.ofInstant(Instant.ofEpochMilli(0L), ZoneId.systemDefault()); private static final ZonedDateTime UPDATED_UPDATED = ZonedDateTime.now(ZoneId.systemDefault()).withNano(0); private static final String DEFAULT_UPDATED_STR = dateTimeFormatter.format(DEFAULT_UPDATED); private static final String DEFAULT_URL = "AAAAA"; private static final String UPDATED_URL = "BBBBB"; @Inject private ApartmentRepository apartmentRepository; @Inject private ApartmentSearchRepository apartmentSearchRepository; @Inject private MappingJackson2HttpMessageConverter jacksonMessageConverter; @Inject private PageableHandlerMethodArgumentResolver pageableArgumentResolver; private MockMvc restApartmentMockMvc; private Apartment apartment; @PostConstruct public void setup() { MockitoAnnotations.initMocks(this); ApartmentResource apartmentResource = new ApartmentResource(); ReflectionTestUtils.setField( apartmentResource, "apartmentSearchRepository", apartmentSearchRepository); ReflectionTestUtils.setField(apartmentResource, "apartmentRepository", apartmentRepository); this.restApartmentMockMvc = MockMvcBuilders.standaloneSetup(apartmentResource) .setCustomArgumentResolvers(pageableArgumentResolver) .setMessageConverters(jacksonMessageConverter) .build(); } @Before public void initTest() { apartment = new Apartment(); apartment.setApartmentId(DEFAULT_APARTMENT_ID); apartment.setCreated(DEFAULT_CREATED); apartment.setUpdated(DEFAULT_UPDATED); apartment.setUrl(DEFAULT_URL); } @Test @Transactional public void createApartment() throws Exception { int databaseSizeBeforeCreate = apartmentRepository.findAll().size(); // Create the Apartment restApartmentMockMvc .perform( post("/api/apartments") .contentType(TestUtil.APPLICATION_JSON_UTF8) .content(TestUtil.convertObjectToJsonBytes(apartment))) .andExpect(status().isCreated()); // Validate the Apartment in the database List<Apartment> apartments = apartmentRepository.findAll(); assertThat(apartments).hasSize(databaseSizeBeforeCreate + 1); Apartment testApartment = apartments.get(apartments.size() - 1); assertThat(testApartment.getApartmentId()).isEqualTo(DEFAULT_APARTMENT_ID); assertThat(testApartment.getCreated()).isEqualTo(DEFAULT_CREATED); assertThat(testApartment.getUpdated()).isEqualTo(DEFAULT_UPDATED); assertThat(testApartment.getUrl()).isEqualTo(DEFAULT_URL); } @Test @Transactional public void checkApartmentIdIsRequired() throws Exception { int databaseSizeBeforeTest = apartmentRepository.findAll().size(); // set the field null apartment.setApartmentId(null); // Create the Apartment, which fails. restApartmentMockMvc .perform( post("/api/apartments") .contentType(TestUtil.APPLICATION_JSON_UTF8) .content(TestUtil.convertObjectToJsonBytes(apartment))) .andExpect(status().isBadRequest()); List<Apartment> apartments = apartmentRepository.findAll(); assertThat(apartments).hasSize(databaseSizeBeforeTest); } @Test @Transactional public void checkCreatedIsRequired() throws Exception { int databaseSizeBeforeTest = apartmentRepository.findAll().size(); // set the field null apartment.setCreated(null); // Create the Apartment, which fails. restApartmentMockMvc .perform( post("/api/apartments") .contentType(TestUtil.APPLICATION_JSON_UTF8) .content(TestUtil.convertObjectToJsonBytes(apartment))) .andExpect(status().isBadRequest()); List<Apartment> apartments = apartmentRepository.findAll(); assertThat(apartments).hasSize(databaseSizeBeforeTest); } @Test @Transactional public void checkUpdatedIsRequired() throws Exception { int databaseSizeBeforeTest = apartmentRepository.findAll().size(); // set the field null apartment.setUpdated(null); // Create the Apartment, which fails. restApartmentMockMvc .perform( post("/api/apartments") .contentType(TestUtil.APPLICATION_JSON_UTF8) .content(TestUtil.convertObjectToJsonBytes(apartment))) .andExpect(status().isBadRequest()); List<Apartment> apartments = apartmentRepository.findAll(); assertThat(apartments).hasSize(databaseSizeBeforeTest); } @Test @Transactional public void getAllApartments() throws Exception { // Initialize the database apartmentRepository.saveAndFlush(apartment); // Get all the apartments restApartmentMockMvc .perform(get("/api/apartments?sort=id,desc")) .andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON)) .andExpect(jsonPath("$.[*].id").value(hasItem(apartment.getId().intValue()))) .andExpect(jsonPath("$.[*].apartmentId").value(hasItem(DEFAULT_APARTMENT_ID.intValue()))) .andExpect(jsonPath("$.[*].created").value(hasItem(DEFAULT_CREATED_STR))) .andExpect(jsonPath("$.[*].updated").value(hasItem(DEFAULT_UPDATED_STR))) .andExpect(jsonPath("$.[*].url").value(hasItem(DEFAULT_URL.toString()))); } @Test @Transactional public void getApartment() throws Exception { // Initialize the database apartmentRepository.saveAndFlush(apartment); // Get the apartment restApartmentMockMvc .perform(get("/api/apartments/{id}", apartment.getId())) .andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON)) .andExpect(jsonPath("$.id").value(apartment.getId().intValue())) .andExpect(jsonPath("$.apartmentId").value(DEFAULT_APARTMENT_ID.intValue())) .andExpect(jsonPath("$.created").value(DEFAULT_CREATED_STR)) .andExpect(jsonPath("$.updated").value(DEFAULT_UPDATED_STR)) .andExpect(jsonPath("$.url").value(DEFAULT_URL.toString())); } @Test @Transactional public void getNonExistingApartment() throws Exception { // Get the apartment restApartmentMockMvc .perform(get("/api/apartments/{id}", Long.MAX_VALUE)) .andExpect(status().isNotFound()); } @Test @Transactional public void updateApartment() throws Exception { // Initialize the database apartmentRepository.saveAndFlush(apartment); int databaseSizeBeforeUpdate = apartmentRepository.findAll().size(); // Update the apartment apartment.setApartmentId(UPDATED_APARTMENT_ID); apartment.setCreated(UPDATED_CREATED); apartment.setUpdated(UPDATED_UPDATED); apartment.setUrl(UPDATED_URL); restApartmentMockMvc .perform( put("/api/apartments") .contentType(TestUtil.APPLICATION_JSON_UTF8) .content(TestUtil.convertObjectToJsonBytes(apartment))) .andExpect(status().isOk()); // Validate the Apartment in the database List<Apartment> apartments = apartmentRepository.findAll(); assertThat(apartments).hasSize(databaseSizeBeforeUpdate); Apartment testApartment = apartments.get(apartments.size() - 1); assertThat(testApartment.getApartmentId()).isEqualTo(UPDATED_APARTMENT_ID); assertThat(testApartment.getCreated()).isEqualTo(UPDATED_CREATED); assertThat(testApartment.getUpdated()).isEqualTo(UPDATED_UPDATED); assertThat(testApartment.getUrl()).isEqualTo(UPDATED_URL); } @Test @Transactional public void deleteApartment() throws Exception { // Initialize the database apartmentRepository.saveAndFlush(apartment); int databaseSizeBeforeDelete = apartmentRepository.findAll().size(); // Get the apartment restApartmentMockMvc .perform( delete("/api/apartments/{id}", apartment.getId()) .accept(TestUtil.APPLICATION_JSON_UTF8)) .andExpect(status().isOk()); // Validate the database is empty List<Apartment> apartments = apartmentRepository.findAll(); assertThat(apartments).hasSize(databaseSizeBeforeDelete - 1); } }
/** Returns a formated {@link String} from the specified {@link Timestamp}. */ public static String format(Instant t) { return tsFormat.format(ZonedDateTime.ofInstant(t, ZoneId.systemDefault())); }
private void setCacheHeaders(ZonedDateTime lastModifiedDate, HttpResponse response) { response.setHeader("Last-Modified", HTTP_DATE_FORMATTER.format(lastModifiedDate)); response.setHeader("Cache-Control", "public,max-age=2592000"); }
/** * Test class for the Register_infoResource REST controller. * * @see Register_infoResource */ @RunWith(SpringJUnit4ClassRunner.class) @SpringApplicationConfiguration(classes = Application.class) @WebAppConfiguration @IntegrationTest public class Register_infoResourceIntTest { private static final DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ISO_OFFSET_DATE_TIME.withZone(ZoneId.of("Z")); private static final LocalDate DEFAULT_DATE_CHECKIN = LocalDate.ofEpochDay(0L); private static final LocalDate UPDATED_DATE_CHECKIN = LocalDate.now(ZoneId.systemDefault()); private static final LocalDate DEFAULT_DATE_CHECKOUT = LocalDate.ofEpochDay(0L); private static final LocalDate UPDATED_DATE_CHECKOUT = LocalDate.now(ZoneId.systemDefault()); private static final Integer DEFAULT_NUMBER_OF_ADULT = 0; private static final Integer UPDATED_NUMBER_OF_ADULT = 1; private static final Integer DEFAULT_NUMBER_OF_KID = 0; private static final Integer UPDATED_NUMBER_OF_KID = 1; private static final String DEFAULT_OTHER_REQUEST = "AAAAA"; private static final String UPDATED_OTHER_REQUEST = "BBBBB"; private static final BigDecimal DEFAULT_DEPOSIT_VALUE = new BigDecimal(0); private static final BigDecimal UPDATED_DEPOSIT_VALUE = new BigDecimal(1); private static final ZonedDateTime DEFAULT_CREATE_DATE = ZonedDateTime.ofInstant(Instant.ofEpochMilli(0L), ZoneId.systemDefault()); private static final ZonedDateTime UPDATED_CREATE_DATE = ZonedDateTime.now(ZoneId.systemDefault()).withNano(0); private static final String DEFAULT_CREATE_DATE_STR = dateTimeFormatter.format(DEFAULT_CREATE_DATE); private static final ZonedDateTime DEFAULT_LAST_MODIFIED_DATE = ZonedDateTime.ofInstant(Instant.ofEpochMilli(0L), ZoneId.systemDefault()); private static final ZonedDateTime UPDATED_LAST_MODIFIED_DATE = ZonedDateTime.now(ZoneId.systemDefault()).withNano(0); private static final String DEFAULT_LAST_MODIFIED_DATE_STR = dateTimeFormatter.format(DEFAULT_LAST_MODIFIED_DATE); @Inject private Register_infoRepository register_infoRepository; @Inject private Register_infoService register_infoService; @Inject private MappingJackson2HttpMessageConverter jacksonMessageConverter; @Inject private PageableHandlerMethodArgumentResolver pageableArgumentResolver; private MockMvc restRegister_infoMockMvc; private Register_info register_info; @PostConstruct public void setup() { MockitoAnnotations.initMocks(this); Register_infoResource register_infoResource = new Register_infoResource(); ReflectionTestUtils.setField( register_infoResource, "register_infoService", register_infoService); this.restRegister_infoMockMvc = MockMvcBuilders.standaloneSetup(register_infoResource) .setCustomArgumentResolvers(pageableArgumentResolver) .setMessageConverters(jacksonMessageConverter) .build(); } @Before public void initTest() { register_info = new Register_info(); register_info.setDate_checkin(DEFAULT_DATE_CHECKIN); register_info.setDate_checkout(DEFAULT_DATE_CHECKOUT); register_info.setNumber_of_adult(DEFAULT_NUMBER_OF_ADULT); register_info.setNumber_of_kid(DEFAULT_NUMBER_OF_KID); register_info.setOther_request(DEFAULT_OTHER_REQUEST); register_info.setDeposit_value(DEFAULT_DEPOSIT_VALUE); register_info.setCreate_date(DEFAULT_CREATE_DATE); register_info.setLast_modified_date(DEFAULT_LAST_MODIFIED_DATE); } @Test @Transactional public void createRegister_info() throws Exception { int databaseSizeBeforeCreate = register_infoRepository.findAll().size(); // Create the Register_info restRegister_infoMockMvc .perform( post("/api/register_infos") .contentType(TestUtil.APPLICATION_JSON_UTF8) .content(TestUtil.convertObjectToJsonBytes(register_info))) .andExpect(status().isCreated()); // Validate the Register_info in the database List<Register_info> register_infos = register_infoRepository.findAll(); assertThat(register_infos).hasSize(databaseSizeBeforeCreate + 1); Register_info testRegister_info = register_infos.get(register_infos.size() - 1); assertThat(testRegister_info.getDate_checkin()).isEqualTo(DEFAULT_DATE_CHECKIN); assertThat(testRegister_info.getDate_checkout()).isEqualTo(DEFAULT_DATE_CHECKOUT); assertThat(testRegister_info.getNumber_of_adult()).isEqualTo(DEFAULT_NUMBER_OF_ADULT); assertThat(testRegister_info.getNumber_of_kid()).isEqualTo(DEFAULT_NUMBER_OF_KID); assertThat(testRegister_info.getOther_request()).isEqualTo(DEFAULT_OTHER_REQUEST); assertThat(testRegister_info.getDeposit_value()).isEqualTo(DEFAULT_DEPOSIT_VALUE); assertThat(testRegister_info.getCreate_date()).isEqualTo(DEFAULT_CREATE_DATE); assertThat(testRegister_info.getLast_modified_date()).isEqualTo(DEFAULT_LAST_MODIFIED_DATE); } @Test @Transactional public void checkDate_checkinIsRequired() throws Exception { int databaseSizeBeforeTest = register_infoRepository.findAll().size(); // set the field null register_info.setDate_checkin(null); // Create the Register_info, which fails. restRegister_infoMockMvc .perform( post("/api/register_infos") .contentType(TestUtil.APPLICATION_JSON_UTF8) .content(TestUtil.convertObjectToJsonBytes(register_info))) .andExpect(status().isBadRequest()); List<Register_info> register_infos = register_infoRepository.findAll(); assertThat(register_infos).hasSize(databaseSizeBeforeTest); } @Test @Transactional public void checkDate_checkoutIsRequired() throws Exception { int databaseSizeBeforeTest = register_infoRepository.findAll().size(); // set the field null register_info.setDate_checkout(null); // Create the Register_info, which fails. restRegister_infoMockMvc .perform( post("/api/register_infos") .contentType(TestUtil.APPLICATION_JSON_UTF8) .content(TestUtil.convertObjectToJsonBytes(register_info))) .andExpect(status().isBadRequest()); List<Register_info> register_infos = register_infoRepository.findAll(); assertThat(register_infos).hasSize(databaseSizeBeforeTest); } @Test @Transactional public void checkNumber_of_adultIsRequired() throws Exception { int databaseSizeBeforeTest = register_infoRepository.findAll().size(); // set the field null register_info.setNumber_of_adult(null); // Create the Register_info, which fails. restRegister_infoMockMvc .perform( post("/api/register_infos") .contentType(TestUtil.APPLICATION_JSON_UTF8) .content(TestUtil.convertObjectToJsonBytes(register_info))) .andExpect(status().isBadRequest()); List<Register_info> register_infos = register_infoRepository.findAll(); assertThat(register_infos).hasSize(databaseSizeBeforeTest); } @Test @Transactional public void checkNumber_of_kidIsRequired() throws Exception { int databaseSizeBeforeTest = register_infoRepository.findAll().size(); // set the field null register_info.setNumber_of_kid(null); // Create the Register_info, which fails. restRegister_infoMockMvc .perform( post("/api/register_infos") .contentType(TestUtil.APPLICATION_JSON_UTF8) .content(TestUtil.convertObjectToJsonBytes(register_info))) .andExpect(status().isBadRequest()); List<Register_info> register_infos = register_infoRepository.findAll(); assertThat(register_infos).hasSize(databaseSizeBeforeTest); } @Test @Transactional public void checkDeposit_valueIsRequired() throws Exception { int databaseSizeBeforeTest = register_infoRepository.findAll().size(); // set the field null register_info.setDeposit_value(null); // Create the Register_info, which fails. restRegister_infoMockMvc .perform( post("/api/register_infos") .contentType(TestUtil.APPLICATION_JSON_UTF8) .content(TestUtil.convertObjectToJsonBytes(register_info))) .andExpect(status().isBadRequest()); List<Register_info> register_infos = register_infoRepository.findAll(); assertThat(register_infos).hasSize(databaseSizeBeforeTest); } @Test @Transactional public void checkCreate_dateIsRequired() throws Exception { int databaseSizeBeforeTest = register_infoRepository.findAll().size(); // set the field null register_info.setCreate_date(null); // Create the Register_info, which fails. restRegister_infoMockMvc .perform( post("/api/register_infos") .contentType(TestUtil.APPLICATION_JSON_UTF8) .content(TestUtil.convertObjectToJsonBytes(register_info))) .andExpect(status().isBadRequest()); List<Register_info> register_infos = register_infoRepository.findAll(); assertThat(register_infos).hasSize(databaseSizeBeforeTest); } @Test @Transactional public void getAllRegister_infos() throws Exception { // Initialize the database register_infoRepository.saveAndFlush(register_info); // Get all the register_infos restRegister_infoMockMvc .perform(get("/api/register_infos?sort=id,desc")) .andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON)) .andExpect(jsonPath("$.[*].id").value(hasItem(register_info.getId().intValue()))) .andExpect(jsonPath("$.[*].date_checkin").value(hasItem(DEFAULT_DATE_CHECKIN.toString()))) .andExpect(jsonPath("$.[*].date_checkout").value(hasItem(DEFAULT_DATE_CHECKOUT.toString()))) .andExpect(jsonPath("$.[*].number_of_adult").value(hasItem(DEFAULT_NUMBER_OF_ADULT))) .andExpect(jsonPath("$.[*].number_of_kid").value(hasItem(DEFAULT_NUMBER_OF_KID))) .andExpect(jsonPath("$.[*].other_request").value(hasItem(DEFAULT_OTHER_REQUEST.toString()))) .andExpect(jsonPath("$.[*].deposit_value").value(hasItem(DEFAULT_DEPOSIT_VALUE.intValue()))) .andExpect(jsonPath("$.[*].create_date").value(hasItem(DEFAULT_CREATE_DATE_STR))) .andExpect( jsonPath("$.[*].last_modified_date").value(hasItem(DEFAULT_LAST_MODIFIED_DATE_STR))); } @Test @Transactional public void getRegister_info() throws Exception { // Initialize the database register_infoRepository.saveAndFlush(register_info); // Get the register_info restRegister_infoMockMvc .perform(get("/api/register_infos/{id}", register_info.getId())) .andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON)) .andExpect(jsonPath("$.id").value(register_info.getId().intValue())) .andExpect(jsonPath("$.date_checkin").value(DEFAULT_DATE_CHECKIN.toString())) .andExpect(jsonPath("$.date_checkout").value(DEFAULT_DATE_CHECKOUT.toString())) .andExpect(jsonPath("$.number_of_adult").value(DEFAULT_NUMBER_OF_ADULT)) .andExpect(jsonPath("$.number_of_kid").value(DEFAULT_NUMBER_OF_KID)) .andExpect(jsonPath("$.other_request").value(DEFAULT_OTHER_REQUEST.toString())) .andExpect(jsonPath("$.deposit_value").value(DEFAULT_DEPOSIT_VALUE.intValue())) .andExpect(jsonPath("$.create_date").value(DEFAULT_CREATE_DATE_STR)) .andExpect(jsonPath("$.last_modified_date").value(DEFAULT_LAST_MODIFIED_DATE_STR)); } @Test @Transactional public void getNonExistingRegister_info() throws Exception { // Get the register_info restRegister_infoMockMvc .perform(get("/api/register_infos/{id}", Long.MAX_VALUE)) .andExpect(status().isNotFound()); } @Test @Transactional public void updateRegister_info() throws Exception { // Initialize the database register_infoRepository.saveAndFlush(register_info); int databaseSizeBeforeUpdate = register_infoRepository.findAll().size(); // Update the register_info register_info.setDate_checkin(UPDATED_DATE_CHECKIN); register_info.setDate_checkout(UPDATED_DATE_CHECKOUT); register_info.setNumber_of_adult(UPDATED_NUMBER_OF_ADULT); register_info.setNumber_of_kid(UPDATED_NUMBER_OF_KID); register_info.setOther_request(UPDATED_OTHER_REQUEST); register_info.setDeposit_value(UPDATED_DEPOSIT_VALUE); register_info.setCreate_date(UPDATED_CREATE_DATE); register_info.setLast_modified_date(UPDATED_LAST_MODIFIED_DATE); restRegister_infoMockMvc .perform( put("/api/register_infos") .contentType(TestUtil.APPLICATION_JSON_UTF8) .content(TestUtil.convertObjectToJsonBytes(register_info))) .andExpect(status().isOk()); // Validate the Register_info in the database List<Register_info> register_infos = register_infoRepository.findAll(); assertThat(register_infos).hasSize(databaseSizeBeforeUpdate); Register_info testRegister_info = register_infos.get(register_infos.size() - 1); assertThat(testRegister_info.getDate_checkin()).isEqualTo(UPDATED_DATE_CHECKIN); assertThat(testRegister_info.getDate_checkout()).isEqualTo(UPDATED_DATE_CHECKOUT); assertThat(testRegister_info.getNumber_of_adult()).isEqualTo(UPDATED_NUMBER_OF_ADULT); assertThat(testRegister_info.getNumber_of_kid()).isEqualTo(UPDATED_NUMBER_OF_KID); assertThat(testRegister_info.getOther_request()).isEqualTo(UPDATED_OTHER_REQUEST); assertThat(testRegister_info.getDeposit_value()).isEqualTo(UPDATED_DEPOSIT_VALUE); assertThat(testRegister_info.getCreate_date()).isEqualTo(UPDATED_CREATE_DATE); assertThat(testRegister_info.getLast_modified_date()).isEqualTo(UPDATED_LAST_MODIFIED_DATE); } @Test @Transactional public void deleteRegister_info() throws Exception { // Initialize the database register_infoRepository.saveAndFlush(register_info); int databaseSizeBeforeDelete = register_infoRepository.findAll().size(); // Get the register_info restRegister_infoMockMvc .perform( delete("/api/register_infos/{id}", register_info.getId()) .accept(TestUtil.APPLICATION_JSON_UTF8)) .andExpect(status().isOk()); // Validate the database is empty List<Register_info> register_infos = register_infoRepository.findAll(); assertThat(register_infos).hasSize(databaseSizeBeforeDelete - 1); } }
/** * Test class for the Bill_serviceResource REST controller. * * @see Bill_serviceResource */ @RunWith(SpringJUnit4ClassRunner.class) @SpringApplicationConfiguration(classes = Application.class) @WebAppConfiguration @IntegrationTest public class Bill_serviceResourceIntTest { private static final DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ISO_OFFSET_DATE_TIME.withZone(ZoneId.of("Z")); private static final Integer DEFAULT_QUANTITY = 0; private static final Integer UPDATED_QUANTITY = 1; private static final BigDecimal DEFAULT_TOTAL = new BigDecimal(0); private static final BigDecimal UPDATED_TOTAL = new BigDecimal(1); private static final String DEFAULT_DECRIPTION = "AAAAA"; private static final String UPDATED_DECRIPTION = "BBBBB"; private static final ZonedDateTime DEFAULT_CREATE_DATE = ZonedDateTime.ofInstant(Instant.ofEpochMilli(0L), ZoneId.systemDefault()); private static final ZonedDateTime UPDATED_CREATE_DATE = ZonedDateTime.now(ZoneId.systemDefault()).withNano(0); private static final String DEFAULT_CREATE_DATE_STR = dateTimeFormatter.format(DEFAULT_CREATE_DATE); @Inject private Bill_serviceRepository bill_serviceRepository; @Inject private Bill_serviceService bill_serviceService; @Inject private MappingJackson2HttpMessageConverter jacksonMessageConverter; @Inject private PageableHandlerMethodArgumentResolver pageableArgumentResolver; private MockMvc restBill_serviceMockMvc; private Bill_service bill_service; @PostConstruct public void setup() { MockitoAnnotations.initMocks(this); Bill_serviceResource bill_serviceResource = new Bill_serviceResource(); ReflectionTestUtils.setField(bill_serviceResource, "bill_serviceService", bill_serviceService); this.restBill_serviceMockMvc = MockMvcBuilders.standaloneSetup(bill_serviceResource) .setCustomArgumentResolvers(pageableArgumentResolver) .setMessageConverters(jacksonMessageConverter) .build(); } @Before public void initTest() { bill_service = new Bill_service(); bill_service.setQuantity(DEFAULT_QUANTITY); bill_service.setTotal(DEFAULT_TOTAL); bill_service.setDecription(DEFAULT_DECRIPTION); bill_service.setCreate_date(DEFAULT_CREATE_DATE); } @Test @Transactional public void createBill_service() throws Exception { int databaseSizeBeforeCreate = bill_serviceRepository.findAll().size(); // Create the Bill_service restBill_serviceMockMvc .perform( post("/api/bill_services") .contentType(TestUtil.APPLICATION_JSON_UTF8) .content(TestUtil.convertObjectToJsonBytes(bill_service))) .andExpect(status().isCreated()); // Validate the Bill_service in the database List<Bill_service> bill_services = bill_serviceRepository.findAll(); assertThat(bill_services).hasSize(databaseSizeBeforeCreate + 1); Bill_service testBill_service = bill_services.get(bill_services.size() - 1); assertThat(testBill_service.getQuantity()).isEqualTo(DEFAULT_QUANTITY); assertThat(testBill_service.getTotal()).isEqualTo(DEFAULT_TOTAL); assertThat(testBill_service.getDecription()).isEqualTo(DEFAULT_DECRIPTION); assertThat(testBill_service.getCreate_date()).isEqualTo(DEFAULT_CREATE_DATE); } @Test @Transactional public void checkQuantityIsRequired() throws Exception { int databaseSizeBeforeTest = bill_serviceRepository.findAll().size(); // set the field null bill_service.setQuantity(null); // Create the Bill_service, which fails. restBill_serviceMockMvc .perform( post("/api/bill_services") .contentType(TestUtil.APPLICATION_JSON_UTF8) .content(TestUtil.convertObjectToJsonBytes(bill_service))) .andExpect(status().isBadRequest()); List<Bill_service> bill_services = bill_serviceRepository.findAll(); assertThat(bill_services).hasSize(databaseSizeBeforeTest); } @Test @Transactional public void checkTotalIsRequired() throws Exception { int databaseSizeBeforeTest = bill_serviceRepository.findAll().size(); // set the field null bill_service.setTotal(null); // Create the Bill_service, which fails. restBill_serviceMockMvc .perform( post("/api/bill_services") .contentType(TestUtil.APPLICATION_JSON_UTF8) .content(TestUtil.convertObjectToJsonBytes(bill_service))) .andExpect(status().isBadRequest()); List<Bill_service> bill_services = bill_serviceRepository.findAll(); assertThat(bill_services).hasSize(databaseSizeBeforeTest); } @Test @Transactional public void checkCreate_dateIsRequired() throws Exception { int databaseSizeBeforeTest = bill_serviceRepository.findAll().size(); // set the field null bill_service.setCreate_date(null); // Create the Bill_service, which fails. restBill_serviceMockMvc .perform( post("/api/bill_services") .contentType(TestUtil.APPLICATION_JSON_UTF8) .content(TestUtil.convertObjectToJsonBytes(bill_service))) .andExpect(status().isBadRequest()); List<Bill_service> bill_services = bill_serviceRepository.findAll(); assertThat(bill_services).hasSize(databaseSizeBeforeTest); } @Test @Transactional public void getAllBill_services() throws Exception { // Initialize the database bill_serviceRepository.saveAndFlush(bill_service); // Get all the bill_services restBill_serviceMockMvc .perform(get("/api/bill_services?sort=id,desc")) .andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON)) .andExpect(jsonPath("$.[*].id").value(hasItem(bill_service.getId().intValue()))) .andExpect(jsonPath("$.[*].quantity").value(hasItem(DEFAULT_QUANTITY))) .andExpect(jsonPath("$.[*].total").value(hasItem(DEFAULT_TOTAL.intValue()))) .andExpect(jsonPath("$.[*].decription").value(hasItem(DEFAULT_DECRIPTION.toString()))) .andExpect(jsonPath("$.[*].create_date").value(hasItem(DEFAULT_CREATE_DATE_STR))); } @Test @Transactional public void getBill_service() throws Exception { // Initialize the database bill_serviceRepository.saveAndFlush(bill_service); // Get the bill_service restBill_serviceMockMvc .perform(get("/api/bill_services/{id}", bill_service.getId())) .andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON)) .andExpect(jsonPath("$.id").value(bill_service.getId().intValue())) .andExpect(jsonPath("$.quantity").value(DEFAULT_QUANTITY)) .andExpect(jsonPath("$.total").value(DEFAULT_TOTAL.intValue())) .andExpect(jsonPath("$.decription").value(DEFAULT_DECRIPTION.toString())) .andExpect(jsonPath("$.create_date").value(DEFAULT_CREATE_DATE_STR)); } @Test @Transactional public void getNonExistingBill_service() throws Exception { // Get the bill_service restBill_serviceMockMvc .perform(get("/api/bill_services/{id}", Long.MAX_VALUE)) .andExpect(status().isNotFound()); } @Test @Transactional public void updateBill_service() throws Exception { // Initialize the database bill_serviceRepository.saveAndFlush(bill_service); int databaseSizeBeforeUpdate = bill_serviceRepository.findAll().size(); // Update the bill_service bill_service.setQuantity(UPDATED_QUANTITY); bill_service.setTotal(UPDATED_TOTAL); bill_service.setDecription(UPDATED_DECRIPTION); bill_service.setCreate_date(UPDATED_CREATE_DATE); restBill_serviceMockMvc .perform( put("/api/bill_services") .contentType(TestUtil.APPLICATION_JSON_UTF8) .content(TestUtil.convertObjectToJsonBytes(bill_service))) .andExpect(status().isOk()); // Validate the Bill_service in the database List<Bill_service> bill_services = bill_serviceRepository.findAll(); assertThat(bill_services).hasSize(databaseSizeBeforeUpdate); Bill_service testBill_service = bill_services.get(bill_services.size() - 1); assertThat(testBill_service.getQuantity()).isEqualTo(UPDATED_QUANTITY); assertThat(testBill_service.getTotal()).isEqualTo(UPDATED_TOTAL); assertThat(testBill_service.getDecription()).isEqualTo(UPDATED_DECRIPTION); assertThat(testBill_service.getCreate_date()).isEqualTo(UPDATED_CREATE_DATE); } @Test @Transactional public void deleteBill_service() throws Exception { // Initialize the database bill_serviceRepository.saveAndFlush(bill_service); int databaseSizeBeforeDelete = bill_serviceRepository.findAll().size(); // Get the bill_service restBill_serviceMockMvc .perform( delete("/api/bill_services/{id}", bill_service.getId()) .accept(TestUtil.APPLICATION_JSON_UTF8)) .andExpect(status().isOk()); // Validate the database is empty List<Bill_service> bill_services = bill_serviceRepository.findAll(); assertThat(bill_services).hasSize(databaseSizeBeforeDelete - 1); } }
/** * Test class for the NewsResource REST controller. * * @see NewsResource */ @RunWith(SpringJUnit4ClassRunner.class) @SpringApplicationConfiguration(classes = Application.class) @WebAppConfiguration @IntegrationTest public class NewsResourceIntTest { private static final DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ISO_OFFSET_DATE_TIME.withZone(ZoneId.of("Z")); private static final String DEFAULT_TITLE = "A"; private static final String UPDATED_TITLE = "B"; private static final ZonedDateTime DEFAULT_DATE = ZonedDateTime.ofInstant(Instant.ofEpochMilli(0L), ZoneId.systemDefault()); private static final ZonedDateTime UPDATED_DATE = ZonedDateTime.now(ZoneId.systemDefault()).withNano(0); private static final String DEFAULT_DATE_STR = dateTimeFormatter.format(DEFAULT_DATE); private static final String DEFAULT_CONTENT = "A"; private static final String UPDATED_CONTENT = "B"; @Inject private NewsRepository newsRepository; @Inject private MappingJackson2HttpMessageConverter jacksonMessageConverter; @Inject private PageableHandlerMethodArgumentResolver pageableArgumentResolver; private MockMvc restNewsMockMvc; private News news; @PostConstruct public void setup() { MockitoAnnotations.initMocks(this); NewsResource newsResource = new NewsResource(); ReflectionTestUtils.setField(newsResource, "newsRepository", newsRepository); this.restNewsMockMvc = MockMvcBuilders.standaloneSetup(newsResource) .setCustomArgumentResolvers(pageableArgumentResolver) .setMessageConverters(jacksonMessageConverter) .build(); } @Before public void initTest() { news = new News(); news.setTitle(DEFAULT_TITLE); news.setDate(DEFAULT_DATE); news.setContent(DEFAULT_CONTENT); } @Test @Transactional public void createNews() throws Exception { int databaseSizeBeforeCreate = newsRepository.findAll().size(); // Create the News restNewsMockMvc .perform( post("/api/newss") .contentType(TestUtil.APPLICATION_JSON_UTF8) .content(TestUtil.convertObjectToJsonBytes(news))) .andExpect(status().isCreated()); // Validate the News in the database List<News> newss = newsRepository.findAll(); assertThat(newss).hasSize(databaseSizeBeforeCreate + 1); News testNews = newss.get(newss.size() - 1); assertThat(testNews.getTitle()).isEqualTo(DEFAULT_TITLE); assertThat(testNews.getDate()).isEqualTo(DEFAULT_DATE); assertThat(testNews.getContent()).isEqualTo(DEFAULT_CONTENT); } @Test @Transactional public void checkTitleIsRequired() throws Exception { int databaseSizeBeforeTest = newsRepository.findAll().size(); // set the field null news.setTitle(null); // Create the News, which fails. restNewsMockMvc .perform( post("/api/newss") .contentType(TestUtil.APPLICATION_JSON_UTF8) .content(TestUtil.convertObjectToJsonBytes(news))) .andExpect(status().isBadRequest()); List<News> newss = newsRepository.findAll(); assertThat(newss).hasSize(databaseSizeBeforeTest); } @Test @Transactional public void checkDateIsRequired() throws Exception { int databaseSizeBeforeTest = newsRepository.findAll().size(); // set the field null news.setDate(null); // Create the News, which fails. restNewsMockMvc .perform( post("/api/newss") .contentType(TestUtil.APPLICATION_JSON_UTF8) .content(TestUtil.convertObjectToJsonBytes(news))) .andExpect(status().isBadRequest()); List<News> newss = newsRepository.findAll(); assertThat(newss).hasSize(databaseSizeBeforeTest); } @Test @Transactional public void checkContentIsRequired() throws Exception { int databaseSizeBeforeTest = newsRepository.findAll().size(); // set the field null news.setContent(null); // Create the News, which fails. restNewsMockMvc .perform( post("/api/newss") .contentType(TestUtil.APPLICATION_JSON_UTF8) .content(TestUtil.convertObjectToJsonBytes(news))) .andExpect(status().isBadRequest()); List<News> newss = newsRepository.findAll(); assertThat(newss).hasSize(databaseSizeBeforeTest); } @Test @Transactional public void getAllNewss() throws Exception { // Initialize the database newsRepository.saveAndFlush(news); // Get all the newss restNewsMockMvc .perform(get("/api/newss?sort=id,desc")) .andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON)) .andExpect(jsonPath("$.[*].id").value(hasItem(news.getId().intValue()))) .andExpect(jsonPath("$.[*].title").value(hasItem(DEFAULT_TITLE.toString()))) .andExpect(jsonPath("$.[*].date").value(hasItem(DEFAULT_DATE_STR))) .andExpect(jsonPath("$.[*].content").value(hasItem(DEFAULT_CONTENT.toString()))); } @Test @Transactional public void getNews() throws Exception { // Initialize the database newsRepository.saveAndFlush(news); // Get the news restNewsMockMvc .perform(get("/api/newss/{id}", news.getId())) .andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON)) .andExpect(jsonPath("$.id").value(news.getId().intValue())) .andExpect(jsonPath("$.title").value(DEFAULT_TITLE.toString())) .andExpect(jsonPath("$.date").value(DEFAULT_DATE_STR)) .andExpect(jsonPath("$.content").value(DEFAULT_CONTENT.toString())); } @Test @Transactional public void getNonExistingNews() throws Exception { // Get the news restNewsMockMvc .perform(get("/api/newss/{id}", Long.MAX_VALUE)) .andExpect(status().isNotFound()); } @Test @Transactional public void updateNews() throws Exception { // Initialize the database newsRepository.saveAndFlush(news); int databaseSizeBeforeUpdate = newsRepository.findAll().size(); // Update the news news.setTitle(UPDATED_TITLE); news.setDate(UPDATED_DATE); news.setContent(UPDATED_CONTENT); restNewsMockMvc .perform( put("/api/newss") .contentType(TestUtil.APPLICATION_JSON_UTF8) .content(TestUtil.convertObjectToJsonBytes(news))) .andExpect(status().isOk()); // Validate the News in the database List<News> newss = newsRepository.findAll(); assertThat(newss).hasSize(databaseSizeBeforeUpdate); News testNews = newss.get(newss.size() - 1); assertThat(testNews.getTitle()).isEqualTo(UPDATED_TITLE); assertThat(testNews.getDate()).isEqualTo(UPDATED_DATE); assertThat(testNews.getContent()).isEqualTo(UPDATED_CONTENT); } @Test @Transactional public void deleteNews() throws Exception { // Initialize the database newsRepository.saveAndFlush(news); int databaseSizeBeforeDelete = newsRepository.findAll().size(); // Get the news restNewsMockMvc .perform(delete("/api/newss/{id}", news.getId()).accept(TestUtil.APPLICATION_JSON_UTF8)) .andExpect(status().isOk()); // Validate the database is empty List<News> newss = newsRepository.findAll(); assertThat(newss).hasSize(databaseSizeBeforeDelete - 1); } }
public String getTimestampElastic() { DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ISO_OFFSET_DATE_TIME.withZone(ZoneId.of("Z")); return dateTimeFormatter.format(timestamp); }