{"action":"created","issue":{"url":"https://api.github.com/repos/jhipster/generator-jhipster/issues/3736","repository_url":"https://api.github.com/repos/jhipster/generator-jhipster","labels_url":"https://api.github.com/repos/jhipster/generator-jhipster/issues/3736/labels{/name}","comments_url":"https://api.github.com/repos/jhipster/generator-jhipster/issues/3736/comments","events_url":"https://api.github.com/repos/jhipster/generator-jhipster/issues/3736/events","html_url":"https://github.com/jhipster/generator-jhipster/issues/3736","id":160919194,"number":3736,"title":"Generated test is wrong","user":{"login":"fraf","id":17450381,"avatar_url":"https://avatars.githubusercontent.com/u/17450381?v=3","gravatar_id":"","url":"https://api.github.com/users/fraf","html_url":"https://github.com/fraf","followers_url":"https://api.github.com/users/fraf/followers","following_url":"https://api.github.com/users/fraf/following{/other_user}","gists_url":"https://api.github.com/users/fraf/gists{/gist_id}","starred_url":"https://api.github.com/users/fraf/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fraf/subscriptions","organizations_url":"https://api.github.com/users/fraf/orgs","repos_url":"https://api.github.com/users/fraf/repos","events_url":"https://api.github.com/users/fraf/events{/privacy}","received_events_url":"https://api.github.com/users/fraf/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-06-17T15:50:47Z","updated_at":"2016-06-17T16:08:48Z","closed_at":"2016-06-17T16:08:48Z","body":"The generated test :\r\n\r\n ```\r\n@Test\r\n    @Transactional\r\n    public void checkPreValidationCertificatIsRequired() throws Exception\r\n    {\r\n        int databaseSizeBeforeTest = informationBanqueEbicsRepository.findAll().size();\r\n        // set the field null\r\n        informationBanqueEbics.setPreValidationCertificat(null);\r\n\r\n        // Create the InformationBanqueEbics, which fails.\r\n\r\n        restInformationBanqueEbicsMockMvc.perform(post(\"/api/informationBanqueEbicss\")\r\n                .contentType(TestUtil.APPLICATION_JSON_UTF8)\r\n                .content(TestUtil.convertObjectToJsonBytes(informationBanqueEbics)))\r\n                .andExpect(status().isBadRequest());\r\n\r\n        List<InformationBanqueEbics> informationBanqueEbicss = informationBanqueEbicsRepository.findAll();\r\n        assertThat(informationBanqueEbicss).hasSize(databaseSizeBeforeTest);\r\n    }\r\n```\r\n\r\nThe entity class :\r\n```\r\n\r\n@Entity\r\n@Table(name = \"STFHPDTB\")\r\n@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)\r\npublic class InformationBanqueEbics extends AbstractAuditingEntity implements Serializable\r\n{\r\n\r\n @NotNull\r\n @Column(name = \"VALCER\", nullable = false)\r\n private Boolean preValidationCertificat;\r\n...\r\n\r\n}\r\n```\r\nThe rest end point : \r\n\r\n```\r\n/**\r\n     * POST  /informationBanqueEbicss -> Create a new informationBanqueEbics.\r\n     */\r\n    @RequestMapping(value = \"/informationBanqueEbicss\", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)\r\n    @Timed\r\n    public ResponseEntity<InformationBanqueEbics> createInformationBanqueEbics(\r\n            @Valid @RequestBody InformationBanqueEbics informationBanqueEbics) throws URISyntaxException\r\n    {\r\n        log.debug(\"REST request to save InformationBanqueEbics : {}\", informationBanqueEbics);\r\n        if (informationBanqueEbics.getId() != null)\r\n        {\r\n            return ResponseEntity.badRequest().headers(HeaderUtil.createFailureAlert(\"informationBanqueEbics\",\r\n                    \"idexists\", \"A new informationBanqueEbics cannot already have an ID\")).body(null);\r\n        }\r\n        InformationBanqueEbics result = informationBanqueEbicsRepository.save(informationBanqueEbics);\r\n        return ResponseEntity.created(new URI(\"/api/informationBanqueEbicss/\" + result.getId()))\r\n                .headers(HeaderUtil.createEntityCreationAlert(\"informationBanqueEbics\", result.getId().toString()))\r\n                .body(result);\r\n    }\r\n```\r\n\r\n\r\n\r\n**The whole code above works fine ! The generated test above works fine ! All is OK !**\r\n\r\n\r\nBut just change the entity class like this :\r\n\r\n```\r\n@NotNull\r\n @Column(name = \"VALCER\", nullable = false)\r\n private Boolean preValidationCertificat = false;\r\n```\r\n\r\n....I just added a default value.\r\nAnd it failed.\r\n\r\nIn fact, this test is useless because JSON transformation DOES ignore null values :\r\n```\r\n\r\n/**\r\n     * Convert an object to JSON byte array.\r\n     *\r\n     * @param object\r\n     *            the object to convert\r\n     * @return the JSON byte array\r\n     * @throws IOException\r\n     */\r\n    public static byte[] convertObjectToJsonBytes(Object object)\r\n            throws IOException {\r\n        ObjectMapper mapper = new ObjectMapper();\r\n        mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);\r\n...\r\n}\r\n```\r\n\r\n\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/jhipster/generator-jhipster/issues/comments/226811526","html_url":"https://github.com/jhipster/generator-jhipster/issues/3736#issuecomment-226811526","issue_url":"https://api.github.com/repos/jhipster/generator-jhipster/issues/3736","id":226811526,"user":{"login":"deepu105","id":1107223,"avatar_url":"https://avatars.githubusercontent.com/u/1107223?v=3","gravatar_id":"","url":"https://api.github.com/users/deepu105","html_url":"https://github.com/deepu105","followers_url":"https://api.github.com/users/deepu105/followers","following_url":"https://api.github.com/users/deepu105/following{/other_user}","gists_url":"https://api.github.com/users/deepu105/gists{/gist_id}","starred_url":"https://api.github.com/users/deepu105/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/deepu105/subscriptions","organizations_url":"https://api.github.com/users/deepu105/orgs","repos_url":"https://api.github.com/users/deepu105/repos","events_url":"https://api.github.com/users/deepu105/events{/privacy}","received_events_url":"https://api.github.com/users/deepu105/received_events","type":"User","site_admin":false},"created_at":"2016-06-17T16:08:48Z","updated_at":"2016-06-17T16:08:48Z","body":"I dont see anything wrong here. The generated test is for the generated entity, if you alter the entity you have to alter the test as well. Simple as that.\r\nThe test checks to see if there is an error thrown when a required field is not set. If yiu set a value always then the error wont be thrown and the test fails and thats a valid failure."}}
{"actor":{"display_login":"deepu105"}}