QProfileLoader profileLoader;
@Test
public void should_generate_app_init_info() throws Exception {
AppAction app = new AppAction(languages, ruleRepositories, i18n, debtModel, profileLoader);
WsTester tester = new WsTester(new RulesWebService(
mock(SearchAction.class), mock(ShowAction.class), mock(TagsAction.class), mock(CreateAction.class),
app, mock(UpdateAction.class), mock(DeleteAction.class)));
MockUserSession.set().setGlobalPermissions(GlobalPermissions.QUALITY_PROFILE_ADMIN);
QualityProfileDto profile1 = QProfileTesting.newXooP1();
QualityProfileDto profile2 = QProfileTesting.newXooP2().setParentKee(QProfileTesting.XOO_P1_KEY);
when(profileLoader.findAll()).thenReturn(ImmutableList.of(profile1, profile2));
Language xoo = mock(Language.class);
when(xoo.getKey()).thenReturn("xoo");
when(xoo.getName()).thenReturn("Xoo");
Language whitespace = mock(Language.class);
when(whitespace.getKey()).thenReturn("ws");
when(whitespace.getName()).thenReturn("Whitespace");
when(languages.get("xoo")).thenReturn(xoo);
when(languages.all()).thenReturn(new Language[]{xoo, whitespace});
RuleRepositories.Repository repo1 = mock(RuleRepositories.Repository.class);
when(repo1.key()).thenReturn("xoo");
when(repo1.name()).thenReturn("SonarQube");
when(repo1.language()).thenReturn("xoo");
RuleRepositories.Repository repo2 = mock(RuleRepositories.Repository.class);
when(repo2.key()).thenReturn("squid");
when(repo2.name()).thenReturn("SonarQube");
when(repo2.language()).thenReturn("ws");
when(ruleRepositories.repositories()).thenReturn(ImmutableList.of(repo1, repo2));
when(i18n.message(isA(Locale.class), anyString(), anyString())).thenAnswer(new Answer<String>() {
@Override
public String answer(InvocationOnMock invocation) throws Throwable {
return (String) invocation.getArguments()[1];
}
});
int parentId = 42;
DefaultDebtCharacteristic char1 = new DefaultDebtCharacteristic();
char1.setId(parentId).setKey("REUSABILITY").setName("Reusability");
DefaultDebtCharacteristic char2 = new DefaultDebtCharacteristic();
char2.setId(24).setParentId(parentId).setKey("MODULARITY").setName("Modularity");
when(debtModel.allCharacteristics()).thenReturn(ImmutableList.<DebtCharacteristic>of(char1, char2));
tester.newGetRequest("api/rules", "app").execute().assertJson(this.getClass(), "app.json");
}