package nc.noumea.mairie.organigramme.utils; /* * #%L * Logiciel de Gestion des Organigrammes de la Ville de Nouméa * $Id:$ * $HeadURL:$ * %% * Copyright (C) 2015 - 2016 Mairie de Nouméa * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public * License along with this program. If not, see * <http://www.gnu.org/licenses/gpl-3.0.html>. * #L% */ import java.util.HashMap; import nc.noumea.mairie.organigramme.dto.EntiteDto; import nc.noumea.mairie.organigramme.dto.FichePosteTreeNodeDto; import nc.noumea.mairie.organigramme.dto.TypeEntiteDto; import org.mockito.Mockito; import org.testng.Assert; import org.testng.annotations.Test; public class EntityUtilsTest { @Test public void getEntiteByIdServiceAds() { EntiteDto niv2_2 = new EntiteDto(); niv2_2.setIdEntite(22); niv2_2.setTypeEntite(new TypeEntiteDto()); niv2_2.getTypeEntite().setLabel("Section"); EntiteDto niv1_2 = new EntiteDto(); niv1_2.setIdEntite(12); niv1_2.setTypeEntite(new TypeEntiteDto()); niv1_2.getTypeEntite().setLabel("Section"); niv1_2.getEnfants().add(niv2_2); EntiteDto niv2_1 = new EntiteDto(); niv2_1.setIdEntite(21); niv2_1.setTypeEntite(new TypeEntiteDto()); niv2_1.getTypeEntite().setLabel(""); EntiteDto niv1_1 = new EntiteDto(); niv1_1.setIdEntite(11); niv1_1.setTypeEntite(new TypeEntiteDto()); niv1_1.getTypeEntite().setLabel("AFFICHAGE SIRH DE TYPE DIRECTION"); niv1_1.getEnfants().add(niv2_1); EntiteDto root = Mockito.spy(new EntiteDto()); root.setIdEntite(1); root.getEnfants().add(niv1_1); root.getEnfants().add(niv1_2); Assert.assertNotNull(EntityUtils.getEntiteByIdServiceAds(niv2_2.getIdEntite(), root)); Assert.assertNull(EntityUtils.getEntiteByIdServiceAds(niv2_2.getIdEntite()+999, root)); } @Test public void getFichesPosteChefDeService_5FichesPostes_5ServicesDifferents() { FichePosteTreeNodeDto niv2_2 = new FichePosteTreeNodeDto(); niv2_2.setIdServiceADS(22); FichePosteTreeNodeDto niv1_2 = new FichePosteTreeNodeDto(); niv1_2.setIdServiceADS(12); niv1_2.getFichePostesEnfant().add(niv2_2); FichePosteTreeNodeDto niv2_1 = new FichePosteTreeNodeDto(); niv2_1.setIdServiceADS(21); FichePosteTreeNodeDto niv1_1 = new FichePosteTreeNodeDto(); niv1_1.setIdServiceADS(11); niv1_1.getFichePostesEnfant().add(niv2_1); FichePosteTreeNodeDto nodeRoot = Mockito.spy(new FichePosteTreeNodeDto()); nodeRoot.setIdServiceADS(1); nodeRoot.getFichePostesEnfant().add(niv1_1); nodeRoot.getFichePostesEnfant().add(niv1_2); HashMap<Integer, FichePosteTreeNodeDto> result = EntityUtils.getFichesPosteChefDeService(nodeRoot); Assert.assertEquals(result.size(), 5); } @Test public void getFichesPosteChefDeService_5FichesPostes_3ServicesDifferents() { FichePosteTreeNodeDto niv2_2 = new FichePosteTreeNodeDto(); niv2_2.setIdServiceADS(21); FichePosteTreeNodeDto niv1_2 = new FichePosteTreeNodeDto(); niv1_2.setIdServiceADS(21); niv1_2.getFichePostesEnfant().add(niv2_2); FichePosteTreeNodeDto niv2_1 = new FichePosteTreeNodeDto(); niv2_1.setIdServiceADS(11); FichePosteTreeNodeDto niv1_1 = new FichePosteTreeNodeDto(); niv1_1.setIdServiceADS(11); niv1_1.getFichePostesEnfant().add(niv2_1); FichePosteTreeNodeDto nodeRoot = Mockito.spy(new FichePosteTreeNodeDto()); nodeRoot.setIdServiceADS(1); nodeRoot.getFichePostesEnfant().add(niv1_1); nodeRoot.getFichePostesEnfant().add(niv1_2); HashMap<Integer, FichePosteTreeNodeDto> result = EntityUtils.getFichesPosteChefDeService(nodeRoot); Assert.assertEquals(result.size(), 3); Assert.assertEquals(result.get(nodeRoot.getIdServiceADS()), nodeRoot); Assert.assertEquals(result.get(niv1_1.getIdServiceADS()), niv1_1); Assert.assertEquals(result.get(niv1_2.getIdServiceADS()), niv1_2); } }