2 * SonarQube, open source software quality management tool.
3 * Copyright (C) 2008-2014 SonarSource
4 * mailto:contact AT sonarsource DOT com
6 * SonarQube is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 3 of the License, or (at your option) any later version.
11 * SonarQube is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 package org.sonar.batch.protocol.output.resource;
22 import org.apache.commons.io.IOUtils;
23 import org.junit.Test;
24 import org.skyscreamer.jsonassert.JSONAssert;
25 import org.sonar.batch.protocol.output.resource.ReportComponent.Type;
27 import java.text.SimpleDateFormat;
28 import java.util.Date;
30 import static org.fest.assertions.Assertions.assertThat;
32 public class ReportComponentsTest {
35 public void to_json() throws Exception {
36 ReportComponents res = new ReportComponents();
37 Date d = new SimpleDateFormat("dd/MM/yyyy").parse("12/12/2012");
38 res.setAnalysisDate(d);
39 ReportComponent root = new ReportComponent()
42 .setName("Root project")
45 ReportComponent module = new ReportComponent()
52 root.addChild(module);
53 ReportComponent dir = new ReportComponent()
61 ReportComponent file = new ReportComponent()
69 .setLanguageKey("java");
75 IOUtils.toString(this.getClass().getResourceAsStream("ReportResourceTest/expected.json"), "UTF-8"),
80 public void from_json() throws Exception {
81 ReportComponents res = ReportComponents
83 IOUtils.toString(this.getClass().getResourceAsStream("ReportResourceTest/expected.json"), "UTF-8"));
85 assertThat(res.analysisDate()).isEqualTo(new SimpleDateFormat("dd/MM/yyyy").parse("12/12/2012"));
86 ReportComponent root = res.root();
87 assertThat(root.batchId()).isEqualTo(1);
88 assertThat(root.id()).isEqualTo(11);
89 assertThat(root.name()).isEqualTo("Root project");
90 assertThat(root.snapshotId()).isEqualTo(111);
91 assertThat(root.path()).isNull();
92 assertThat(root.type()).isEqualTo(Type.PRJ);
93 assertThat(root.children()).hasSize(1);
94 assertThat(root.isTest()).isNull();
95 assertThat(root.languageKey()).isNull();