@Test public void fail_if_not_logged_in() throws Exception { userSessionRule.anonymous(); expectedException.expect(UnauthorizedException.class); MetricDto metric = MetricTesting.newMetricDto().setEnabled(true).setValueType(ValueType.STRING.name()); dbClient.metricDao().insert(dbSession, metric); ComponentDto component = ComponentTesting.newProjectDto("project-uuid"); dbClient.componentDao().insert(dbSession, component); CustomMeasureDto customMeasure = newCustomMeasureDto() .setMetricId(metric.getId()) .setComponentUuid(component.uuid()) .setCreatedAt(system.now()) .setDescription("custom-measure-description") .setTextValue("text-measure-value"); dbClient.customMeasureDao().insert(dbSession, customMeasure); dbSession.commit(); ws.newPostRequest(CustomMeasuresWs.ENDPOINT, UpdateAction.ACTION) .setParam(PARAM_ID, String.valueOf(customMeasure.getId())) .setParam(PARAM_DESCRIPTION, "new-custom-measure-description") .setParam(PARAM_VALUE, "1984") .execute(); }
@Test public void returns_full_object_in_response() throws Exception { MetricDto metric = MetricTesting.newMetricDto() .setEnabled(true) .setValueType(ValueType.STRING.name()) .setKey("metric-key"); dbClient.metricDao().insert(dbSession, metric); ComponentDto component = ComponentTesting.newProjectDto("project-uuid").setKey("project-key"); dbClient.componentDao().insert(dbSession, component); CustomMeasureDto customMeasure = newCustomMeasure(component, metric) .setCreatedAt(100_000_000L) .setDescription("custom-measure-description") .setTextValue("text-measure-value"); dbClient.customMeasureDao().insert(dbSession, customMeasure); dbSession.commit(); when(system.now()).thenReturn(123_456_789L); WsTester.Result response = ws.newPostRequest(CustomMeasuresWs.ENDPOINT, UpdateAction.ACTION) .setParam(PARAM_ID, String.valueOf(customMeasure.getId())) .setParam(PARAM_DESCRIPTION, "new-custom-measure-description") .setParam(PARAM_VALUE, "new-text-measure-value") .execute(); response.assertJson(getClass(), "custom-measure.json"); String responseAsString = response.outputAsString(); assertThat(responseAsString) .matches(String.format(".*\"id\"\\s*:\\s*\"%s\".*", customMeasure.getId())); assertThat(responseAsString) .matches(String.format(".*\"id\"\\s*:\\s*\"%s\".*", metric.getId())); assertThat(responseAsString).matches(".*createdAt.*updatedAt.*"); }