| 1 | |
package br.mia.test.model.algoritmo; |
| 2 | |
|
| 3 | |
import java.io.FileNotFoundException; |
| 4 | |
import java.io.IOException; |
| 5 | |
import java.io.UnsupportedEncodingException; |
| 6 | |
import java.sql.SQLException; |
| 7 | |
import java.util.ArrayList; |
| 8 | |
import java.util.HashMap; |
| 9 | |
import java.util.List; |
| 10 | |
|
| 11 | |
import org.apache.log4j.Logger; |
| 12 | |
|
| 13 | |
import br.mia.test.controler.ControladorErro; |
| 14 | |
import br.mia.test.model.CasoUso; |
| 15 | |
import br.mia.test.model.CodeFactorySelenium; |
| 16 | |
import br.mia.test.model.CodeFactoryXDE; |
| 17 | |
import br.mia.test.model.Filtro; |
| 18 | |
import br.mia.test.model.Fluxo; |
| 19 | |
import br.mia.test.model.ItemData; |
| 20 | |
import br.mia.test.model.Link; |
| 21 | |
import br.mia.test.model.Projeto; |
| 22 | |
import br.mia.test.model.RegraNegocio; |
| 23 | |
import br.mia.test.model.RegraNegocioStep; |
| 24 | |
import br.mia.test.model.RuleDelete; |
| 25 | |
import br.mia.test.model.Step; |
| 26 | |
import br.mia.test.model.TestDataValor; |
| 27 | |
import br.mia.test.testcase.CasoTesteStep; |
| 28 | |
import br.mia.test.testcase.CasosTeste; |
| 29 | |
import br.mia.test.testcase.CasosTesteCodigo; |
| 30 | |
import br.mia.test.testcase.DadosTeste; |
| 31 | |
import br.mia.test.util.Util; |
| 32 | |
|
| 33 | |
import com.lowagie.text.html.HtmlEncoder; |
| 34 | |
|
| 35 | |
|
| 36 | |
|
| 37 | |
|
| 38 | 0 | |
| 39 | |
|
| 40 | |
|
| 41 | 0 | public class Algoritmo |
| 42 | 0 | { |
| 43 | |
|
| 44 | 0 | private StringBuffer filtrosAplicados; |
| 45 | 0 | |
| 46 | 0 | public StringBuffer getFiltrosAplicados() { |
| 47 | 0 | return filtrosAplicados; |
| 48 | 0 | } |
| 49 | 0 | |
| 50 | |
public void setFiltrosAplicados(StringBuffer filtrosAplicados) { |
| 51 | 0 | this.filtrosAplicados = filtrosAplicados; |
| 52 | 0 | } |
| 53 | 0 | |
| 54 | 0 | private ArrayList<TestDataValor> valoresTeste = new ArrayList<TestDataValor>(); |
| 55 | 0 | |
| 56 | 0 | private HashMap<String, RegraNegocio> regrasCobertas; |
| 57 | |
|
| 58 | 0 | boolean adicionarCasoTeste = true; |
| 59 | |
|
| 60 | 0 | private ArrayList<CasosTeste> casosDeTeste = new ArrayList<CasosTeste>(); |
| 61 | |
|
| 62 | 0 | private ArrayList<CasosTeste> casosDeTesteData = new ArrayList<CasosTeste>(); |
| 63 | 0 | |
| 64 | 0 | private static HashMap<String, Fluxo> flows = new HashMap<String, Fluxo>(); |
| 65 | |
|
| 66 | 0 | public HashMap<String, RegraNegocio> getRegrasCobertas() { |
| 67 | 0 | return regrasCobertas; |
| 68 | 0 | } |
| 69 | 0 | |
| 70 | 0 | public void setRegrasCobertas(HashMap<String, RegraNegocio> regrasCobertas) { |
| 71 | 0 | this.regrasCobertas = regrasCobertas; |
| 72 | 0 | } |
| 73 | 0 | |
| 74 | 0 | |
| 75 | 0 | |
| 76 | 0 | |
| 77 | 0 | |
| 78 | 0 | |
| 79 | |
|
| 80 | |
public void limpaArvore(CasoUso useCase) { |
| 81 | 0 | |
| 82 | 0 | for (Object element : useCase.getFlows()) { |
| 83 | 0 | Fluxo flow = (Fluxo) element; |
| 84 | 0 | for (Object element1 : flow.getSteps()) { |
| 85 | 0 | Step step = (Step) element1; |
| 86 | 0 | step.setCoberto(false); |
| 87 | 0 | step.setNumberOfExecution(0); |
| 88 | |
|
| 89 | |
} |
| 90 | 0 | flows.put(flow.getName(), flow); |
| 91 | |
|
| 92 | |
} |
| 93 | |
|
| 94 | 0 | } |
| 95 | |
|
| 96 | |
|
| 97 | |
|
| 98 | |
|
| 99 | |
|
| 100 | |
|
| 101 | |
|
| 102 | |
|
| 103 | |
|
| 104 | 0 | |
| 105 | 0 | |
| 106 | 0 | |
| 107 | |
|
| 108 | 0 | |
| 109 | 0 | |
| 110 | 0 | |
| 111 | 0 | |
| 112 | 0 | |
| 113 | 0 | |
| 114 | 0 | |
| 115 | 0 | public void applyDataValue(ArrayList<ItemData> dados, CasosTeste testCase, |
| 116 | 0 | int posicao, CasosTeste novoCasoAux, int nivel, String passo, |
| 117 | 0 | String descricao, CasoUso useCase, Step step, DadosTeste data) |
| 118 | 0 | throws InstantiationException, IllegalAccessException, |
| 119 | 0 | ClassNotFoundException, SQLException, IOException { |
| 120 | |
|
| 121 | 0 | ItemData item = (ItemData) dados.get(nivel); |
| 122 | 0 | HashMap<Object, Object> mapaAntigo = new HashMap<Object, Object>(); |
| 123 | 0 | mapaAntigo.putAll(novoCasoAux.getClasses()); |
| 124 | |
String passoOriginal; |
| 125 | 0 | for (Object object : item.getItemFilhos()) { |
| 126 | 0 | novoCasoAux.setClasses(new HashMap<Object, Object>()); |
| 127 | 0 | novoCasoAux.getClasses().putAll(mapaAntigo); |
| 128 | 0 | TestDataValor valor = (TestDataValor) object; |
| 129 | 0 | Logger logger=Util.getLogger(); |
| 130 | 0 | logger.info("Aplicando Valor :"+useCase.getName()+":"+step.getFluxo().getName()+":"+valor.getValor()); |
| 131 | 0 | |
| 132 | 0 | if (!(novoCasoAux.isCoberturaFiltro())) { |
| 133 | 0 | |
| 134 | 0 | if ((!(valor.isValid())) && (!(valor.isValorEsperado()))) { |
| 135 | 0 | |
| 136 | 0 | novoCasoAux.setValid(false); |
| 137 | 0 | novoCasoAux.setCoberturaFiltro(true); |
| 138 | 0 | |
| 139 | 0 | logger.info("Aplica Valores :"+useCase.getName()+":"+step.getFluxo().getName()+":"+valor.getValor()); |
| 140 | 0 | |
| 141 | 0 | } else { |
| 142 | 0 | novoCasoAux.setValid(true); |
| 143 | 0 | |
| 144 | 0 | } |
| 145 | 0 | |
| 146 | |
} |
| 147 | 0 | |
| 148 | 0 | if ((valor.getResultadoEsperado() != null) |
| 149 | 0 | && (valor.getResultadoEsperado().toString().length() > 0)) { |
| 150 | 0 | |
| 151 | 0 | String valorEsperado = " (" |
| 152 | 0 | + valor.getResultadoEsperado().toString() + " )"; |
| 153 | 0 | CasoUso.getResultadosValidos().put( |
| 154 | 0 | item.getTestData().getName(), valorEsperado); |
| 155 | |
|
| 156 | |
} |
| 157 | |
|
| 158 | 0 | passoOriginal = passo; |
| 159 | 0 | |
| 160 | 0 | String[] valores = valor.getValor().toString().split("\n"); |
| 161 | 0 | |
| 162 | 0 | if ((valor.getClasse() != null) && (valor.getClasse().length() > 0)) { |
| 163 | 0 | if (!(novoCasoAux.getClasses().containsKey(valor.getClasse() |
| 164 | 0 | .toString()))) { |
| 165 | 0 | novoCasoAux.getClasses().put(valor.getClasse().toString(), |
| 166 | 0 | valor.getClasse()); |
| 167 | 0 | } |
| 168 | 0 | } |
| 169 | 0 | |
| 170 | 0 | if ((nivel < dados.size() - 1) && (testCase.isNormal())) { |
| 171 | 0 | |
| 172 | 0 | applyDataValue(dados, testCase, posicao, novoCasoAux, |
| 173 | 0 | nivel + 1, passo, descricao, useCase, step, data); |
| 174 | 0 | |
| 175 | 0 | } else { |
| 176 | 0 | |
| 177 | 0 | CasosTeste novoCaso = new CasosTeste(); |
| 178 | 0 | novoCaso.setValid(novoCasoAux.isValid()); |
| 179 | 0 | novoCaso.setCoberturaFiltro(novoCasoAux.isCoberturaFiltro()); |
| 180 | 0 | HashMap<Object, Object> novaClasse = new HashMap<Object, Object>(); |
| 181 | 0 | novaClasse.putAll(novoCasoAux.getClasses()); |
| 182 | 0 | novoCaso.setClasses(novaClasse); |
| 183 | 0 | if (!(valor.isValid())) { |
| 184 | 0 | if (testCase.isNormal()) { |
| 185 | 0 | novoCaso.setNormal(false); |
| 186 | 0 | novoCaso.setInvalidData(item.getTestData()); |
| 187 | 0 | |
| 188 | 0 | } |
| 189 | 0 | |
| 190 | 0 | } else { |
| 191 | 0 | |
| 192 | 0 | novoCaso.setNormal(novoCasoAux.isNormal()); |
| 193 | 0 | novoCaso.setInvalidData(novoCasoAux.getInvalidData()); |
| 194 | 0 | } |
| 195 | 0 | novoCaso.setNumeroCasosTeste(novoCasoAux.getNumeroCasosTeste()); |
| 196 | 0 | novoCaso.getPassos().addAll(novoCasoAux.getPassos()); |
| 197 | 0 | novoCaso.getFlows().addAll(novoCasoAux.getFlows()); |
| 198 | 0 | novoCaso.setEntradas(novoCasoAux.getEntradas()); |
| 199 | 0 | novoCaso.setSaidasEsperadas(novoCasoAux.getSaidasEsperadas()); |
| 200 | 0 | novoCaso.getResultadoEsperado().append( |
| 201 | 0 | novoCasoAux.getResultadoEsperado()); |
| 202 | 0 | |
| 203 | 0 | for (int i = 0; i <= valores.length - 1; i++) { |
| 204 | 0 | Step novoStep = new Step(); |
| 205 | 0 | |
| 206 | 0 | String novoPasso = passo.replaceAll(item.getCard(), |
| 207 | 0 | valores[i]); |
| 208 | 0 | |
| 209 | 0 | if ((valor.getResultadoEsperado() != null) |
| 210 | 0 | && (valor.getResultadoEsperado().toString() |
| 211 | 0 | .length() > 0)) { |
| 212 | 0 | if (novoCaso.getSaidasEsperadas() == null) { |
| 213 | 0 | novoCaso.setSaidasEsperadas(""); |
| 214 | |
} |
| 215 | 0 | if (!(novoCaso.getSaidasEsperadas().contains(valor |
| 216 | 0 | .getResultadoEsperado().toString()))) { |
| 217 | 0 | |
| 218 | 0 | novoCaso.setSaidasEsperadas(valor |
| 219 | 0 | .getResultadoEsperado().toString()); |
| 220 | 0 | } |
| 221 | |
} |
| 222 | |
|
| 223 | 0 | if (novoCaso.getEntradas() == null) { |
| 224 | 0 | novoCaso.setEntradas(""); |
| 225 | 0 | } |
| 226 | 0 | |
| 227 | 0 | if (!(novoCaso.getEntradas() |
| 228 | 0 | .contains(valores[i].toString()))) { |
| 229 | 0 | |
| 230 | 0 | novoCaso.setEntradas(novoCaso.getEntradas() + " " |
| 231 | 0 | + valores[i].toString()); |
| 232 | 0 | |
| 233 | |
} |
| 234 | 0 | |
| 235 | 0 | novoStep.setDescricaoOriginal(passoOriginal); |
| 236 | 0 | novoStep.setDescricao(novoPasso); |
| 237 | 0 | novoStep.setDatas(step.getDatas()); |
| 238 | |
|
| 239 | 0 | CasoTesteStep casoTesteStep = new CasoTesteStep(); |
| 240 | 0 | |
| 241 | 0 | casoTesteStep.setStep(novoStep); |
| 242 | |
|
| 243 | 0 | novoCaso.getPassos().add(casoTesteStep); |
| 244 | 0 | } |
| 245 | 0 | |
| 246 | 0 | if (testCase.getNumeroCasosTeste() > testCase |
| 247 | 0 | .getNumeroMaximoCasosTeste()) { |
| 248 | 0 | return; |
| 249 | 0 | } |
| 250 | |
|
| 251 | 0 | applyData(testCase, posicao + 1, novoCaso, useCase, |
| 252 | 0 | adicionarCasoTeste); |
| 253 | 0 | |
| 254 | 0 | } |
| 255 | 0 | |
| 256 | 0 | passo = descricao; |
| 257 | 0 | |
| 258 | 0 | } |
| 259 | 0 | } |
| 260 | 0 | |
| 261 | 0 | public void applyCode(CasosTeste testCase, int posicao, String linguagem) |
| 262 | |
throws InstantiationException, IllegalAccessException, |
| 263 | 0 | ClassNotFoundException, SQLException, FileNotFoundException { |
| 264 | 0 | |
| 265 | 0 | while (posicao <= testCase.getPassos().size() - 1) { |
| 266 | |
|
| 267 | 0 | Step step = (Step) testCase.getPassos().get(posicao).getStep(); |
| 268 | 0 | if (step.getDatas().size() <= 0) { |
| 269 | 0 | String code = ""; |
| 270 | 0 | if (linguagem.equals("XDE")) { |
| 271 | 0 | code = CodeFactoryXDE.gera(step.getTipoObjeto(), step |
| 272 | 0 | .getPalavraChave(), "", step.getDescricao()); |
| 273 | 0 | } |
| 274 | 0 | if (linguagem.equals("Selenium")) { |
| 275 | 0 | code = CodeFactorySelenium.gera(step.getTipoObjeto(), step |
| 276 | 0 | .getPalavraChave(), "", step.getDescricao()); |
| 277 | 0 | } |
| 278 | |
|
| 279 | 0 | String descricao = code; |
| 280 | 0 | step.setDescricao(descricao); |
| 281 | 0 | } else { |
| 282 | 0 | |
| 283 | 0 | String wildCard = ""; |
| 284 | 0 | for (int i = 0; i <= step.getDatas().size() - 1; i++) { |
| 285 | 0 | |
| 286 | 0 | DadosTeste testData = (DadosTeste) step.getDatas().get(i); |
| 287 | 0 | |
| 288 | 0 | wildCard += testData.getCard() + " "; |
| 289 | 0 | |
| 290 | |
} |
| 291 | 0 | |
| 292 | 0 | String code = CodeFactoryXDE.gera(step.getTipoObjeto(), step |
| 293 | 0 | .getPalavraChave(), wildCard, step.getDescricao()); |
| 294 | 0 | String descricao = code; |
| 295 | 0 | step.setDescricao(descricao); |
| 296 | |
|
| 297 | 0 | } |
| 298 | 0 | posicao++; |
| 299 | |
|
| 300 | 0 | } |
| 301 | 0 | |
| 302 | 0 | } |
| 303 | |
|
| 304 | 0 | |
| 305 | 0 | |
| 306 | 0 | |
| 307 | 0 | |
| 308 | 0 | |
| 309 | |
|
| 310 | 0 | |
| 311 | |
|
| 312 | 0 | |
| 313 | |
|
| 314 | 0 | |
| 315 | 0 | |
| 316 | |
|
| 317 | 0 | |
| 318 | |
|
| 319 | 0 | public void applyData(CasosTeste testCase, int posicao, |
| 320 | |
CasosTeste novoCasodeTeste, CasoUso useCase, boolean adicionar) |
| 321 | 0 | throws InstantiationException, IllegalAccessException, |
| 322 | 0 | ClassNotFoundException, SQLException, IOException { |
| 323 | 0 | |
| 324 | 0 | novoCasodeTeste.getFlows().addAll(testCase.getFlows()); |
| 325 | 0 | |
| 326 | 0 | DadosTeste testData = null; |
| 327 | 0 | |
| 328 | 0 | while (posicao <= testCase.getPassos().size() - 1) { |
| 329 | 0 | |
| 330 | 0 | Step step = (Step) testCase.getPassos().get(posicao).getStep(); |
| 331 | 0 | |
| 332 | 0 | String descricao = step.getDescricao(); |
| 333 | |
|
| 334 | 0 | if (step.getDatas().size() > 0) { |
| 335 | 0 | ArrayList<ItemData> dados = new ArrayList<ItemData>(); |
| 336 | 0 | for (int i = 0; i <= step.getDatas().size() - 1; i++) { |
| 337 | 0 | ArrayList<TestDataValor> array = new ArrayList<TestDataValor>(); |
| 338 | 0 | testData = (DadosTeste) step.getDatas().get(i); |
| 339 | 0 | |
| 340 | 0 | boolean isResult = false; |
| 341 | 0 | |
| 342 | 0 | List<TestDataValor> valores = null; |
| 343 | 0 | if (testData.isResult()) { |
| 344 | 0 | String resultado = ""; |
| 345 | 0 | |
| 346 | 0 | if (CasoUso.getResultadosValidos().containsKey( |
| 347 | 0 | testData.getName().replace("vp", ""))) { |
| 348 | 0 | resultado = CasoUso.getResultadosValidos().get( |
| 349 | 0 | testData.getName().replace("vp", "")) |
| 350 | 0 | .toString(); |
| 351 | 0 | |
| 352 | 0 | isResult = true; |
| 353 | 0 | |
| 354 | 0 | TestDataValor valorEsperado = new TestDataValor(); |
| 355 | 0 | |
| 356 | 0 | valorEsperado.setDadoteste(testData); |
| 357 | |
|
| 358 | 0 | valorEsperado.setValor(resultado); |
| 359 | 0 | valorEsperado.setValorEsperado(true); |
| 360 | 0 | valorEsperado.setResultadoEsperado(resultado); |
| 361 | 0 | |
| 362 | 0 | array.add(valorEsperado); |
| 363 | 0 | |
| 364 | 0 | } |
| 365 | 0 | |
| 366 | 0 | } |
| 367 | |
|
| 368 | 0 | ItemData item = new ItemData(); |
| 369 | 0 | item.setTestData(testData); |
| 370 | 0 | item.setCard(testData.getCard()); |
| 371 | 0 | if (isResult) { |
| 372 | 0 | item.getItemFilhos().addAll(array); |
| 373 | 0 | } else { |
| 374 | 0 | item.getItemFilhos().addAll(testData.getValues()); |
| 375 | 0 | } |
| 376 | 0 | dados.add(item); |
| 377 | 0 | } |
| 378 | 0 | |
| 379 | 0 | boolean apply = true; |
| 380 | 0 | |
| 381 | 0 | List<Filtro> filtros = step.getFiltros(); |
| 382 | 0 | |
| 383 | 0 | for (Filtro filtro : filtros) { |
| 384 | |
|
| 385 | 0 | if (filtro.getTipoFiltro() == 1) { |
| 386 | 0 | if (!(novoCasodeTeste.isValid())) { |
| 387 | 0 | adicionar = false; |
| 388 | 0 | apply = false; |
| 389 | 0 | break; |
| 390 | 0 | } |
| 391 | 0 | |
| 392 | 0 | } |
| 393 | 0 | if (filtro.getTipoFiltro() == 0) { |
| 394 | 0 | if ((novoCasodeTeste.isValid())) { |
| 395 | 0 | adicionar = false; |
| 396 | 0 | apply = false; |
| 397 | 0 | break; |
| 398 | 0 | } |
| 399 | 0 | |
| 400 | 0 | } |
| 401 | 0 | if (filtro.getTipoFiltro() == 2) { |
| 402 | 0 | if (filtro.getClasse() != null) { |
| 403 | 0 | if (!(novoCasodeTeste.getClasses() |
| 404 | 0 | .containsKey(filtro.getClasse().toString()))) { |
| 405 | 0 | adicionar = false; |
| 406 | 0 | apply = false; |
| 407 | 0 | Util.getLogger().info("Filtro:"+useCase.getName()+":"+step.getFluxo().getName()+"N�o encontado classe " |
| 408 | 0 | + filtro.getClasse() |
| 409 | 0 | + " no passo " |
| 410 | 0 | + step.getDescricao() |
| 411 | 0 | + " classes encontradas neste passo " |
| 412 | 0 | + novoCasodeTeste.getClasses() |
| 413 | 0 | .values()+" \n"); |
| 414 | 0 | break; |
| 415 | 0 | } else { |
| 416 | 0 | adicionar = true; |
| 417 | 0 | apply = true; |
| 418 | 0 | break; |
| 419 | 0 | } |
| 420 | 0 | } |
| 421 | |
|
| 422 | |
} |
| 423 | 0 | } |
| 424 | 0 | |
| 425 | 0 | if (apply) { |
| 426 | 0 | this.applyDataValue(dados, testCase, posicao, |
| 427 | 0 | novoCasodeTeste, 0, descricao, descricao, useCase, |
| 428 | 0 | step, testData); |
| 429 | 0 | } |
| 430 | 0 | |
| 431 | 0 | adicionar = false; |
| 432 | 0 | |
| 433 | 0 | break; |
| 434 | 0 | |
| 435 | 0 | } else { |
| 436 | 0 | |
| 437 | 0 | boolean apply = true; |
| 438 | 0 | for (Filtro filtro : step.getFiltros()) { |
| 439 | |
|
| 440 | 0 | if (filtro.getTipoFiltro() == 1) { |
| 441 | 0 | if (!(novoCasodeTeste.isValid())) { |
| 442 | 0 | adicionar = false; |
| 443 | 0 | apply = false; |
| 444 | 0 | break; |
| 445 | |
} |
| 446 | 0 | |
| 447 | 0 | } |
| 448 | 0 | if (filtro.getTipoFiltro() == 0) { |
| 449 | 0 | if ((novoCasodeTeste.isValid())) { |
| 450 | 0 | adicionar = false; |
| 451 | 0 | apply = false; |
| 452 | 0 | break; |
| 453 | 0 | } |
| 454 | 0 | |
| 455 | |
} |
| 456 | 0 | if (filtro.getTipoFiltro() == 2) { |
| 457 | 0 | if (filtro.getClasse() != null) { |
| 458 | 0 | if (!(novoCasodeTeste.getClasses() |
| 459 | 0 | .containsKey(filtro.getClasse().toString()))) { |
| 460 | 0 | adicionar = false; |
| 461 | 0 | apply = false; |
| 462 | 0 | Util.getLogger().info("Filtro:"+useCase.getName()+":"+step.getFluxo().getName()+"N�o encontado classe " |
| 463 | 0 | + filtro.getClasse() |
| 464 | 0 | + " no passo " |
| 465 | 0 | + step.getDescricao() |
| 466 | 0 | + " classes encontradas neste passo " |
| 467 | 0 | + novoCasodeTeste.getClasses() |
| 468 | 0 | .values()+" \n"); |
| 469 | 0 | |
| 470 | 0 | break; |
| 471 | |
} else { |
| 472 | 0 | adicionar = true; |
| 473 | 0 | apply = true; |
| 474 | 0 | break; |
| 475 | 0 | } |
| 476 | 0 | } |
| 477 | 0 | |
| 478 | 0 | } |
| 479 | 0 | } |
| 480 | 0 | |
| 481 | 0 | if (!(apply)) { |
| 482 | 0 | break; |
| 483 | 0 | } |
| 484 | 0 | |
| 485 | 0 | CasoTesteStep casoTesteStep = new CasoTesteStep(); |
| 486 | |
|
| 487 | 0 | casoTesteStep.setStep(step); |
| 488 | |
|
| 489 | 0 | novoCasodeTeste.getPassos().add(casoTesteStep); |
| 490 | 0 | |
| 491 | 0 | } |
| 492 | 0 | |
| 493 | 0 | for (Filtro filtro : step.getFiltros()) { |
| 494 | 0 | |
| 495 | 0 | if (filtro.getTipoFiltro() == 1) { |
| 496 | 0 | if (!(novoCasodeTeste.isValid())) { |
| 497 | 0 | adicionar = false; |
| 498 | 0 | break; |
| 499 | 0 | } |
| 500 | 0 | |
| 501 | |
} |
| 502 | 0 | if (filtro.getTipoFiltro() == 0) { |
| 503 | 0 | if ((novoCasodeTeste.isValid())) { |
| 504 | 0 | adicionar = false; |
| 505 | 0 | break; |
| 506 | 0 | } |
| 507 | 0 | |
| 508 | |
} |
| 509 | 0 | if (filtro.getTipoFiltro() == 2) { |
| 510 | 0 | if (filtro.getClasse() != null) { |
| 511 | 0 | if (!(novoCasodeTeste.getClasses().containsKey(filtro |
| 512 | 0 | .getClasse().toString()))) { |
| 513 | 0 | adicionar = false; |
| 514 | 0 | break; |
| 515 | 0 | } else { |
| 516 | 0 | adicionar = true; |
| 517 | 0 | break; |
| 518 | 0 | } |
| 519 | 0 | |
| 520 | 0 | } |
| 521 | |
|
| 522 | 0 | } |
| 523 | 0 | } |
| 524 | 0 | posicao++; |
| 525 | 0 | |
| 526 | 0 | } |
| 527 | 0 | |
| 528 | 0 | if (adicionar) { |
| 529 | 0 | testCase.setNumeroCasosTeste(testCase.getNumeroCasosTeste() + 1); |
| 530 | 0 | Util.getLogger().info("CASOTESTE:Adicionado Caso de Teste dos Fluxos "+novoCasodeTeste.getFlows()+"\n"); |
| 531 | 0 | Util.getLogger().info("CASOTESTE:Adicionado Caso de Teste das Classes "+novoCasodeTeste.getClasses()+"\n"); |
| 532 | 0 | this.casosDeTesteData.add(novoCasodeTeste); |
| 533 | 0 | } |
| 534 | 0 | |
| 535 | 0 | } |
| 536 | |
|
| 537 | |
|
| 538 | 0 | |
| 539 | 0 | |
| 540 | 0 | |
| 541 | 0 | |
| 542 | 0 | |
| 543 | 0 | |
| 544 | 0 | public boolean verificaFiltro(Step step, CasosTeste testCase) { |
| 545 | 0 | |
| 546 | 0 | boolean para = false; |
| 547 | 0 | |
| 548 | 0 | for (Filtro filtro : step.getFiltros()) { |
| 549 | |
|
| 550 | 0 | if (filtro.getTipoFiltro() == 1) { |
| 551 | 0 | if (!(testCase.isValid())) { |
| 552 | 0 | adicionarCasoTeste = false; |
| 553 | 0 | para = true; |
| 554 | |
} |
| 555 | |
|
| 556 | 0 | } |
| 557 | 0 | if (filtro.getTipoFiltro() == 0) { |
| 558 | 0 | if ((testCase.isValid())) { |
| 559 | 0 | adicionarCasoTeste = false; |
| 560 | 0 | para = true; |
| 561 | 0 | } |
| 562 | 0 | |
| 563 | 0 | } |
| 564 | 0 | if (filtro.getTipoFiltro() == 2) { |
| 565 | 0 | if (step.getClasse() != null) { |
| 566 | 0 | if (!(testCase.getClasses().containsKey(step.getClasse() |
| 567 | 0 | .toString()))) { |
| 568 | 0 | adicionarCasoTeste = false; |
| 569 | 0 | para = true; |
| 570 | 0 | } else { |
| 571 | 0 | adicionarCasoTeste = true; |
| 572 | 0 | para = false; |
| 573 | 0 | break; |
| 574 | 0 | |
| 575 | 0 | } |
| 576 | 0 | } |
| 577 | |
|
| 578 | 0 | } |
| 579 | |
} |
| 580 | 0 | |
| 581 | 0 | return para; |
| 582 | 0 | } |
| 583 | 0 | |
| 584 | 0 | public void retornaCenarios(Fluxo flow, int number, CasosTeste casoTeste, |
| 585 | 0 | int points, CasoUso useCase) { |
| 586 | 0 | |
| 587 | 0 | try { |
| 588 | 0 | if (!(Algoritmo.flows.containsKey(flow.getName()))) { |
| 589 | 0 | Algoritmo.flows.put(flow.getName(), flow); |
| 590 | 0 | } |
| 591 | 0 | |
| 592 | 0 | casoTeste.getFlows().add(flow); |
| 593 | 0 | |
| 594 | 0 | while (number <= flow.getSteps().size() - 1) { |
| 595 | 0 | |
| 596 | 0 | Step step = (Step) ((Fluxo) Algoritmo.flows.get(flow.getName())) |
| 597 | 0 | .getSteps().get(number); |
| 598 | 0 | |
| 599 | 0 | CasoTesteStep casoTesteStep = new CasoTesteStep(); |
| 600 | 0 | |
| 601 | 0 | casoTesteStep.setStep(step); |
| 602 | |
|
| 603 | 0 | casoTeste.getPassos().add(casoTesteStep); |
| 604 | 0 | step.setCoberto(true); |
| 605 | 0 | int numeroExecucoes = step.getNumberOfExecution(); |
| 606 | 0 | if (numeroExecucoes > (useCase.getFlows().size() * 2)) { |
| 607 | 0 | break; |
| 608 | 0 | } |
| 609 | 0 | step.setNumberOfExecution(numeroExecucoes + 1); |
| 610 | 0 | |
| 611 | 0 | if (step.getRegras().size() > 0) { |
| 612 | 0 | for (int i = 0; i <= step.getRegras().size() - 1; i++) { |
| 613 | 0 | RegraNegocio regra = ((RegraNegocio) step.getRegras() |
| 614 | 0 | .get(i)); |
| 615 | 0 | |
| 616 | 0 | if ((!(this.regrasCobertas.containsKey(regra.getName()))) |
| 617 | 0 | || (regra.isReuse())) { |
| 618 | 0 | |
| 619 | 0 | for (RegraNegocioStep stepRegra : regra.getSteps()) { |
| 620 | |
|
| 621 | 0 | CasoTesteStep casoStep = new CasoTesteStep(); |
| 622 | 0 | |
| 623 | 0 | casoStep.setStep(stepRegra.toStep()); |
| 624 | 0 | |
| 625 | 0 | casoTeste.getPassos().add(casoStep); |
| 626 | 0 | } |
| 627 | 0 | if (!(regra.isReuse())) { |
| 628 | 0 | this.regrasCobertas.put(regra.getName(), regra); |
| 629 | 0 | } |
| 630 | 0 | } |
| 631 | 0 | |
| 632 | 0 | } |
| 633 | 0 | |
| 634 | 0 | } |
| 635 | 0 | |
| 636 | 0 | if (step.getLinks().size() > 0) { |
| 637 | 0 | for (int i = 0; i <= step.getLinks().size() - 1; i++) { |
| 638 | 0 | |
| 639 | 0 | Link link1 = ((Link) step.getLinks().get(i)); |
| 640 | 0 | if (link1.getFlow() != null) { |
| 641 | 0 | if (!(Algoritmo.flows.containsKey(link1.getFlow() |
| 642 | 0 | .getName()))) { |
| 643 | 0 | Algoritmo.flows.put(link1.getFlow().getName(), |
| 644 | 0 | link1.getFlow()); |
| 645 | 0 | } |
| 646 | 0 | if (((Fluxo) (Algoritmo.flows.get(link1.getFlow() |
| 647 | 0 | .getName()))).steps.size() == 0) { |
| 648 | 0 | Algoritmo.flows.put(link1.getFlow().getName(), |
| 649 | 0 | link1.getFlow()); |
| 650 | 0 | } |
| 651 | 0 | |
| 652 | 0 | if (Fluxo.getStepNumber(((Fluxo) Algoritmo.flows |
| 653 | 0 | .get(link1.getFlow().getName()))) != Fluxo |
| 654 | 0 | .getStepNumberCover(((Fluxo) Algoritmo.flows |
| 655 | 0 | .get(link1.getFlow().getName())))) { |
| 656 | 0 | |
| 657 | 0 | CasosTeste casoTeste1 = new CasosTeste(); |
| 658 | 0 | casoTeste1.getFlows().addAll( |
| 659 | 0 | casoTeste.getFlows()); |
| 660 | 0 | casoTeste1.getPassos().addAll(0, |
| 661 | 0 | casoTeste.getPassos()); |
| 662 | 0 | |
| 663 | 0 | RuleDelete ruleDelete = new RuleDelete(); |
| 664 | 0 | ruleDelete.ruleDelete(casoTeste1, this |
| 665 | 0 | .getRegrasCobertas()); |
| 666 | 0 | |
| 667 | 0 | retornaCenarios(((Fluxo) Algoritmo.flows |
| 668 | 0 | .get(link1.getFlow().getName())), link1 |
| 669 | 0 | .getStepNumber(), casoTeste1, points, |
| 670 | 0 | useCase); |
| 671 | 0 | |
| 672 | 0 | } |
| 673 | 0 | } |
| 674 | 0 | |
| 675 | 0 | } |
| 676 | 0 | } |
| 677 | 0 | number++; |
| 678 | 0 | } |
| 679 | 0 | |
| 680 | 0 | casoTeste.setNumeroMaximoCasosTeste(flow.getNumeroMaximo()); |
| 681 | 0 | casosDeTeste.add(casoTeste); |
| 682 | 0 | } catch (StackOverflowError e) { |
| 683 | 0 | casoTeste.setNumeroMaximoCasosTeste(flow.getNumeroMaximo()); |
| 684 | 0 | casosDeTeste.add(casoTeste); |
| 685 | 0 | } |
| 686 | 0 | |
| 687 | 0 | } |
| 688 | 0 | |
| 689 | 0 | public Algoritmo() { |
| 690 | 0 | this.regrasCobertas = new HashMap<String, RegraNegocio>(); |
| 691 | 0 | this.filtrosAplicados = new StringBuffer(); |
| 692 | 0 | } |
| 693 | 0 | |
| 694 | 0 | public String mostra() { |
| 695 | 0 | StringBuffer buffer = new StringBuffer(); |
| 696 | 0 | for (int i = 0; i <= this.casosDeTesteData.size() - 1; i++) { |
| 697 | 0 | buffer.append(this.casosDeTesteData.get(i)); |
| 698 | 0 | |
| 699 | 0 | } |
| 700 | 0 | return buffer.toString(); |
| 701 | 0 | } |
| 702 | 0 | |
| 703 | 0 | public String mostraCode(CasoUso useCase, |
| 704 | 0 | ArrayList<CasosTesteCodigo> casosTeste, String linguagem) { |
| 705 | 0 | StringBuffer buffer = new StringBuffer(); |
| 706 | 0 | for (int i = 0; i <= casosTeste.size() - 1; i++) { |
| 707 | 0 | CasosTesteCodigo testCase = (CasosTesteCodigo) casosTeste.get(i); |
| 708 | 0 | buffer.append(useCase.getSetUp() + "\n"); |
| 709 | 0 | if (linguagem.equals("Selenium")) { |
| 710 | 0 | buffer.append(testCase.toStringSelenium(useCase.getName() |
| 711 | 0 | + "-CT", i)); |
| 712 | 0 | |
| 713 | 0 | } else { |
| 714 | 0 | buffer.append(testCase.toString()); |
| 715 | 0 | } |
| 716 | 0 | buffer.append(useCase.getTearDown() + "\n"); |
| 717 | 0 | |
| 718 | 0 | } |
| 719 | 0 | return buffer.toString(); |
| 720 | 0 | } |
| 721 | 0 | |
| 722 | 0 | public String mostraTestManager(Projeto projeto, CasoUso useCase) { |
| 723 | 0 | StringBuffer buffer = new StringBuffer(); |
| 724 | 0 | buffer |
| 725 | 0 | .append("<?xml version=\"1.0\"?>\n<TestAssetParcel>\n<TestPlan>\n<Name><![CDATA[Test Plan 1]]></Name>"); |
| 726 | 0 | buffer |
| 727 | 0 | .append("\n <Description/>\n <CreationDate><![CDATA[2008:02:26:13:44:02]]></CreationDate>"); |
| 728 | 0 | buffer |
| 729 | 0 | .append("\n<ModificationDate><![CDATA[2008:02:26:13:44:02]]></ModificationDate>"); |
| 730 | 0 | buffer |
| 731 | 0 | .append("\n<LastModifiedBy><![CDATA[TestManagementSystem]]></LastModifiedBy>"); |
| 732 | 0 | buffer |
| 733 | 0 | .append("\n<CreatedBy><![CDATA[TestManagementSystem]]></CreatedBy>"); |
| 734 | 0 | buffer.append("\n<Owner><![CDATA[TestManagementSystem]]></Owner>"); |
| 735 | 0 | buffer.append("\n<Custom1/>"); |
| 736 | 0 | buffer.append("\n<Custom2/><Custom3/>"); |
| 737 | 0 | buffer.append("\n<ExternalDocument-List/>"); |
| 738 | 0 | buffer |
| 739 | 0 | .append("\n<Iteration-List/>\n<Configuration-List/>\n<TestCaseFolder>"); |
| 740 | 0 | buffer.append("\n<Name><![CDATA[" |
| 741 | 0 | + this.tiraCaracteres(useCase.getName()) + "]]></Name>"); |
| 742 | 0 | buffer |
| 743 | 0 | .append("\n<Description/>\n<CreationDate><![CDATA[2008:02:26:13:44:02]]></CreationDate>"); |
| 744 | 0 | buffer |
| 745 | 0 | .append("\n<ModificationDate>\n<![CDATA[2008:02:26:13:44:02]]>\n</ModificationDate>"); |
| 746 | 0 | buffer |
| 747 | 0 | .append("\n<LastModifiedBy>\n<![CDATA[TestManagementSystem]]>\n</LastModifiedBy>"); |
| 748 | 0 | buffer |
| 749 | 0 | .append("\n<CreatedBy>\n<![CDATA[TestManagementSystem]]>\n</CreatedBy>"); |
| 750 | 0 | buffer.append("\n<Owner>\n<![CDATA[TestManagementSystem]]>\n</Owner>"); |
| 751 | 0 | buffer.append("\n<Iteration-List/>"); |
| 752 | 0 | buffer.append("\n<Configuration-List/>"); |
| 753 | 0 | |
| 754 | 0 | for (int i = 0; i <= this.casosDeTesteData.size() - 1; i++) { |
| 755 | 0 | buffer.append("\n<TestCase>"); |
| 756 | 0 | CasosTeste test = this.casosDeTesteData.get(i); |
| 757 | 0 | String nomeCasoUso = useCase.getName(); |
| 758 | 0 | if (nomeCasoUso.length() >= 20) { |
| 759 | 0 | nomeCasoUso = nomeCasoUso.substring(0, 19); |
| 760 | 0 | } |
| 761 | 0 | String descricao = "Caso de teste que realiza os testes de sistema dos fluxos:\n"; |
| 762 | 0 | List<Fluxo> fluxos = test.getFlows(); |
| 763 | 0 | for (Object object : fluxos) { |
| 764 | |
|
| 765 | 0 | Fluxo flow = (Fluxo) object; |
| 766 | 0 | String novoFluxo = this.tiraCaracteres(flow.getName()); |
| 767 | |
|
| 768 | 0 | if (!(descricao.contains(novoFluxo))) { |
| 769 | 0 | descricao += novoFluxo + "\n"; |
| 770 | |
} |
| 771 | |
|
| 772 | 0 | } |
| 773 | 0 | buffer.append("\n<Name><![CDATA[" |
| 774 | 0 | + this.tiraCaracteres(nomeCasoUso + "-CT") + i |
| 775 | 0 | + "]]></Name>"); |
| 776 | 0 | buffer.append("\n<Description>"); |
| 777 | 0 | buffer.append("\n<![CDATA["); |
| 778 | 0 | buffer.append(descricao); |
| 779 | 0 | buffer.append("]]></Description>"); |
| 780 | 0 | buffer |
| 781 | 0 | .append("\n<CreationDate><![CDATA[2008:02:26:13:44:35]]></CreationDate>"); |
| 782 | 0 | buffer |
| 783 | 0 | .append("\n<ModificationDate>\n<![CDATA[2008:02:26:13:46:01]]>\n</ModificationDate>"); |
| 784 | 0 | buffer |
| 785 | 0 | .append("\n<LastModifiedBy>\n<![CDATA[admin]]>\n</LastModifiedBy>"); |
| 786 | 0 | buffer.append("\n<CreatedBy>\n<![CDATA[admin]]>\n</CreatedBy>"); |
| 787 | 0 | buffer.append("\n<Owner>\n<![CDATA[admin]]>\n</Owner>"); |
| 788 | 0 | buffer |
| 789 | 0 | .append("\n<Purpose/>\n<Custom1/>\n<Custom2/>\n<Custom3/>\n<Preconditions/>"); |
| 790 | 0 | buffer |
| 791 | 0 | .append("\n<PreconditionsInherited><![CDATA[0]]></PreconditionsInherited>"); |
| 792 | 0 | buffer |
| 793 | 0 | .append("\n<Postconditions/>" |
| 794 | |
+ "\n<PostconditionsInherited><![CDATA[0]]></PostconditionsInherited>" |
| 795 | |
+ "\n<Configured><![CDATA[0]]></Configured>" |
| 796 | 0 | + "\n<Suspect><![CDATA[0]]></Suspect>" |
| 797 | 0 | + "\n<ExternalDocument-List/>" |
| 798 | 0 | + "\n<TestInput-List/>" |
| 799 | 0 | + "\n<AcceptanceCriteria/>" |
| 800 | 0 | + "\n<AcceptanceCriteriaInherited><![CDATA[0]]></AcceptanceCriteriaInherited>" |
| 801 | |
+ "\n<AutoImplementationInherited><![CDATA[0]]></AutoImplementationInherited>" |
| 802 | 0 | + "\n<ManualImplementation>" |
| 803 | 0 | + "<ScriptName><![CDATA[" |
| 804 | 0 | + this.tiraCaracteres(nomeCasoUso) |
| 805 | 0 | + "-CT" |
| 806 | 0 | + i |
| 807 | 0 | + "]]></ScriptName>" |
| 808 | 0 | + "<ScriptSource><![CDATA[Manual - (Rational Test Datastore)]]></ScriptSource>" |
| 809 | 0 | + "</ManualImplementation>" |
| 810 | 0 | + "<ManualImplementationInherited><![CDATA[0]]></ManualImplementationInherited>" |
| 811 | 0 | + "\n<DesignStep-List>"); |
| 812 | 0 | List<CasoTesteStep> steps = test.getPassos(); |
| 813 | 0 | |
| 814 | 0 | for (CasoTesteStep casoTesteStep : steps) { |
| 815 | 0 | |
| 816 | 0 | Step element = casoTesteStep.getStep(); |
| 817 | 0 | buffer.append("\n<DesignStep>\n<Type><![CDATA[Step]]></Type>"); |
| 818 | 0 | buffer.append("\n<Description><![CDATA[" |
| 819 | 0 | + this.tiraCaracteres(element.getDescricao()) |
| 820 | 0 | + "]]></Description>"); |
| 821 | 0 | buffer |
| 822 | 0 | .append("\n<Notes><![CDATA[@@none]]></Notes>\n</DesignStep>"); |
| 823 | 0 | |
| 824 | 0 | } |
| 825 | 0 | buffer.append("\n</DesignStep-List>" |
| 826 | 0 | + "\n<ExecutionOption-List/>\n<State><![CDATA[0]]></State>" |
| 827 | 0 | + "\n<StateComment/>" + "\n<Points><![CDATA[1]]></Points>" |
| 828 | 0 | + "\n<PointsInherited><![CDATA[0]]></PointsInherited>" |
| 829 | |
+ "\n<PointsAttempted><![CDATA[0]]></PointsAttempted>" |
| 830 | 0 | + "\n<PointsPass><![CDATA[0]]></PointsPass>" |
| 831 | |
+ "\n<PointsFail><![CDATA[0]]></PointsFail>" |
| 832 | 0 | + "\n<Iteration-List/>" + "\n<Configuration-List/>" |
| 833 | 0 | + "\n<Input-List/>" + "\n</TestCase>"); |
| 834 | 0 | |
| 835 | 0 | } |
| 836 | 0 | buffer.append("</TestCaseFolder> </TestPlan>"); |
| 837 | 0 | buffer |
| 838 | 0 | .append("\n<TestScriptSource>" |
| 839 | |
+ " \n <Name><![CDATA[Manual - (Rational Test Datastore)]]></Name>" |
| 840 | |
+ "\n<Description/>" |
| 841 | |
+ " \n <CreationDate><![CDATA[2008:02:26:13:44:01]]></CreationDate>" |
| 842 | |
+ "\n<ModificationDate><![CDATA[2008:02:26:13:44:01]]></ModificationDate>" |
| 843 | 0 | + " \n <LastModifiedBy><![CDATA[TestManagementSystem]]></LastModifiedBy>" |
| 844 | 0 | + "\n<CreatedBy><![CDATA[TestManagementSystem]]></CreatedBy>" |
| 845 | 0 | + " \n <Owner><![CDATA[TestManagementSystem]]></Owner>" |
| 846 | 0 | + "\n<DataPath><![CDATA[0]]></DataPath>" |
| 847 | 0 | + " \n <DataPathSpecificity><![CDATA[0]]></DataPathSpecificity>" |
| 848 | |
+ "\n<ConfigurationData/>" |
| 849 | |
+ " \n <ConnectionOption-List>" |
| 850 | 0 | + "\n<ConnectionOption>" |
| 851 | 0 | + "\n<Name><![CDATA[Default Datastore]]></Name>" |
| 852 | 0 | + " \n <Op/>" |
| 853 | 0 | + "\n<Value><![CDATA[1]]></Value>" |
| 854 | |
+ "\n</ConnectionOption>" |
| 855 | 0 | + " \n <ConnectionOption>" |
| 856 | |
+ "\n<Name><![CDATA[Type]]></Name>" |
| 857 | |
+ " \n <Op/>" |
| 858 | |
+ "\n<Value><![CDATA[Manual]]></Value>" |
| 859 | |
+ "\n</ConnectionOption>" |
| 860 | 0 | + "\n</ConnectionOption-List>" |
| 861 | 0 | + " \n <Flags><![CDATA[0]]></Flags>" |
| 862 | 0 | + "\n<ExecutionOption-List/>" |
| 863 | 0 | + " \n <DatapoolPath/>" |
| 864 | 0 | + "\n<DatapoolPathSpecificity><![CDATA[0]]></DatapoolPathSpecificity>" |
| 865 | 0 | + " \n <EnableVersioning><![CDATA[0]]></EnableVersioning>" |
| 866 | 0 | + "\n<Associated-ScriptType><![CDATA[Manual Script]]></Associated-ScriptType>" |
| 867 | 0 | + "\n</TestScriptSource>" |
| 868 | 0 | + " \n <TestScriptType>" |
| 869 | 0 | + "\n<Name><![CDATA[Manual Script]]></Name>" |
| 870 | 0 | + " \n <Description/>" |
| 871 | 0 | + "\n<CreationDate><![CDATA[2008:02:26:13:44:01]]></CreationDate>" |
| 872 | 0 | + " \n <ModificationDate><![CDATA[2008:02:26:13:44:01]]></ModificationDate>" |
| 873 | 0 | + "\n<LastModifiedBy><![CDATA[TestManagementSystem]]></LastModifiedBy>" |
| 874 | 0 | + " \n <CreatedBy><![CDATA[TestManagementSystem]]></CreatedBy>" |
| 875 | 0 | + "\n<Owner><![CDATA[TestManagementSystem]]></Owner>" |
| 876 | 0 | + " \n <ConsoleAdapterName><![CDATA[rtconsoleadapter]]></ConsoleAdapterName>" |
| 877 | 0 | + "\n<ExecutionAdapterName><![CDATA[rttseacmd]]></ExecutionAdapterName>" |
| 878 | 0 | + " \n <ConsoleAdapterType><![CDATA[1]]></ConsoleAdapterType>" |
| 879 | 0 | + "\n<ExecutionAdapterType><![CDATA[2]]></ExecutionAdapterType>" |
| 880 | 0 | + " \n <NewMethod/>" |
| 881 | 0 | + "\n<EditMethod/>" |
| 882 | 0 | + " \n <SelectMethod/>" |
| 883 | 0 | + "\n<RecordMethod/>" |
| 884 | 0 | + " \n <ExecutionMethod><![CDATA[RTManualTest -run {testscript} -project \"{project}\" -user \"{username}\" -password \"{password}\"]]></ExecutionMethod>" |
| 885 | 0 | + "\n<ExecutionOption-List/>" |
| 886 | 0 | + " \n <SelectUseFileDlg><![CDATA[0]]></SelectUseFileDlg>" |
| 887 | 0 | + "\n<ConsoleAdapterPath/>" |
| 888 | 0 | + " \n <ExecutionAdapterPath/>" |
| 889 | 0 | + "\n<Flags><![CDATA[0]]></Flags>" |
| 890 | 0 | + " \n <Type><![CDATA[32]]></Type>" |
| 891 | 0 | + "\n<MaxTesters><![CDATA[1]]></MaxTesters>" |
| 892 | 0 | + " \n <ScriptSource-List>" |
| 893 | 0 | + "\n<Associated-ScriptSource><![CDATA[Manual - (Rational Test Datastore)]]></Associated-ScriptSource>" |
| 894 | 0 | + "\n</ScriptSource-List>" + "\n</TestScriptType>"); |
| 895 | 0 | for (int i = 0; i <= this.casosDeTesteData.size() - 1; i++) { |
| 896 | 0 | CasosTeste test = this.casosDeTesteData.get(i); |
| 897 | 0 | String nomeCasoUso = useCase.getName(); |
| 898 | 0 | if (nomeCasoUso.length() >= 20) { |
| 899 | 0 | nomeCasoUso = nomeCasoUso.substring(0, 19); |
| 900 | 0 | } |
| 901 | 0 | buffer |
| 902 | 0 | .append("\n<Script>" + "\n<Name><![CDATA[" |
| 903 | 0 | + this.tiraCaracteres(nomeCasoUso) |
| 904 | 0 | + "-CT" |
| 905 | 0 | + i |
| 906 | 0 | + "]]></Name>" |
| 907 | 0 | + " \n <Description/>" |
| 908 | 0 | + "\n<CreationDate><![CDATA[2008:02:26:18:06:19]]></CreationDate>" |
| 909 | 0 | + " \n <ModificationDate><![CDATA[2008:02:26:18:06:19]]></ModificationDate>" |
| 910 | 0 | + "\n<LastModifiedBy><![CDATA[admin]]></LastModifiedBy>" |
| 911 | 0 | + " \n <CreatedBy><![CDATA[admin]]></CreatedBy>" |
| 912 | 0 | + "\n<Owner><![CDATA[admin]]></Owner>" |
| 913 | 0 | + " \n <Purpose/>" + "\n<Environment/>" |
| 914 | 0 | + " \n <Type><![CDATA[32]]></Type>" |
| 915 | 0 | + "\n<TypeName><![CDATA[Manual]]></TypeName>" |
| 916 | 0 | + " \n <Custom1/>" + "\n<Custom2/>" |
| 917 | 0 | + " \n <Custom3/>" |
| 918 | 0 | + "\n<Developed><![CDATA[0]]></Developed>" |
| 919 | 0 | + " \n <SpecFilePath/>" + "\n<SpecNotes/>" |
| 920 | 0 | + " \n<Define-List/>" + "\n<Library-List/>" |
| 921 | 0 | + " \n<ClassPath/>" + "\n<DesignStep-List>"); |
| 922 | 0 | List<CasoTesteStep> steps = test.getPassos(); |
| 923 | 0 | for (CasoTesteStep casoTesteStep : steps) { |
| 924 | 0 | |
| 925 | 0 | Step element = casoTesteStep.getStep(); |
| 926 | 0 | if (!(this.pontoVerificacao(element.getDescricao()))) { |
| 927 | 0 | buffer |
| 928 | 0 | .append("\n<DesignStep>\n<Type><![CDATA[Step]]></Type>"); |
| 929 | |
} else { |
| 930 | 0 | buffer.append("\n<DesignStep><Type><![CDATA[VP]]></Type>"); |
| 931 | 0 | } |
| 932 | 0 | buffer.append("\n<Description><![CDATA[" |
| 933 | 0 | + this.tiraCaracteres(element.getDescricao()) |
| 934 | 0 | + "]]></Description>"); |
| 935 | 0 | buffer |
| 936 | 0 | .append("\n<Notes><![CDATA[@@none]]></Notes>\n" |
| 937 | 0 | + "\n<ExpectedResult><![CDATA[@@none]]></ExpectedResult>" |
| 938 | 0 | + "\n<ExpectedResultFile><![CDATA[@@none]]></ExpectedResultFile>" |
| 939 | 0 | + "\n</DesignStep>"); |
| 940 | 0 | |
| 941 | |
} |
| 942 | 0 | |
| 943 | 0 | buffer.append("\n</DesignStep-List>"); |
| 944 | 0 | buffer.append("\n<FilePath><![CDATA[TMS_Scripts\\" |
| 945 | 0 | + this.tiraCaracteres(nomeCasoUso) + "-CT" + i |
| 946 | 0 | + ".]]></FilePath>"); |
| 947 | 0 | buffer.append("\n</Script>"); |
| 948 | 0 | |
| 949 | 0 | } |
| 950 | 0 | buffer.append("\n<ScriptFiles>"); |
| 951 | 0 | buffer.append("\n<ScriptFile-List/>"); |
| 952 | 0 | buffer.append("\n</ScriptFiles>"); |
| 953 | 0 | buffer.append("\n</TestAssetParcel>"); |
| 954 | 0 | |
| 955 | 0 | return buffer.toString(); |
| 956 | 0 | } |
| 957 | 0 | |
| 958 | 0 | |
| 959 | 0 | |
| 960 | |
|
| 961 | 0 | |
| 962 | 0 | |
| 963 | 0 | |
| 964 | 0 | |
| 965 | 0 | |
| 966 | 0 | public String mostraTestLink(Projeto projeto, CasoUso useCase) |
| 967 | 0 | throws IOException { |
| 968 | 0 | StringBuffer buffer = new StringBuffer(); |
| 969 | 0 | buffer.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?><testcases>"); |
| 970 | 0 | String regra = Util.getPropriedade("testcasename"); |
| 971 | 0 | for (int i = 0; i <= this.casosDeTesteData.size() - 1; i++) { |
| 972 | 0 | CasosTeste test = this.casosDeTesteData.get(i); |
| 973 | 0 | |
| 974 | 0 | String nome; |
| 975 | 0 | |
| 976 | 0 | if (regra != null) { |
| 977 | 0 | if (regra.contains("FN")) { |
| 978 | |
|
| 979 | 0 | StringBuffer nomeFluxo = new StringBuffer(); |
| 980 | 0 | for (Fluxo flow : test.getFlows()) { |
| 981 | 0 | String nomeReduzido = flow.getName().substring(0, 2); |
| 982 | 0 | |
| 983 | 0 | if (!(nomeFluxo.toString().contains(nomeReduzido))) { |
| 984 | 0 | |
| 985 | 0 | nomeFluxo.append(nomeReduzido); |
| 986 | 0 | } |
| 987 | 0 | } |
| 988 | 0 | nome = useCase.getName() + nomeFluxo.toString() + "-CT" + i; |
| 989 | 0 | |
| 990 | 0 | } else { |
| 991 | 0 | nome = useCase.getName() + "-CT" + i; |
| 992 | 0 | } |
| 993 | 0 | if (regra.contains("DT")) { |
| 994 | 0 | nome += (new java.util.Date()).toString(); |
| 995 | 0 | } |
| 996 | 0 | |
| 997 | 0 | } else { |
| 998 | 0 | nome = useCase.getName() + "-CT" + i; |
| 999 | |
|
| 1000 | 0 | } |
| 1001 | 0 | buffer.append("<testcase name=\"" + nome + "\">"); |
| 1002 | 0 | |
| 1003 | 0 | String descricao = "Caso de teste que realiza os testes de sistema dos fluxos:"; |
| 1004 | 0 | |
| 1005 | 0 | List<Fluxo> fluxos = test.getFlows(); |
| 1006 | 0 | for (Object object : fluxos) { |
| 1007 | 0 | |
| 1008 | 0 | Fluxo flow = (Fluxo) object; |
| 1009 | 0 | String novoFluxo = this.tiraCaracteres(flow.getName()); |
| 1010 | 0 | |
| 1011 | 0 | if (!(descricao.contains(novoFluxo))) { |
| 1012 | 0 | descricao += novoFluxo + "<br>"; |
| 1013 | |
} |
| 1014 | 0 | |
| 1015 | |
} |
| 1016 | 0 | |
| 1017 | 0 | buffer.append("<summary><![CDATA[" + descricao + "]]></summary>"); |
| 1018 | 0 | buffer.append("<steps><![CDATA["); |
| 1019 | 0 | List<CasoTesteStep> steps = test.getPassos(); |
| 1020 | 0 | for (CasoTesteStep casoTesteStep : steps) { |
| 1021 | 0 | |
| 1022 | 0 | Step element = casoTesteStep.getStep(); |
| 1023 | 0 | String passo; |
| 1024 | 0 | try { |
| 1025 | 0 | passo = new String( |
| 1026 | 0 | element.getDescricao().getBytes("UTF-8"), "UTF-8"); |
| 1027 | 0 | buffer.append(HtmlEncoder.encode(passo) + "<br>"); |
| 1028 | 0 | |
| 1029 | 0 | } catch (UnsupportedEncodingException erro) { |
| 1030 | 0 | ControladorErro.trata(erro, this); |
| 1031 | 0 | } |
| 1032 | 0 | |
| 1033 | 0 | } |
| 1034 | 0 | buffer |
| 1035 | 0 | .append("]]></steps><expectedresults><![CDATA[]]></expectedresults>"); |
| 1036 | 0 | buffer.append("</testcase>"); |
| 1037 | 0 | } |
| 1038 | 0 | |
| 1039 | 0 | buffer.append("</testcases>"); |
| 1040 | 0 | return buffer.toString(); |
| 1041 | 0 | } |
| 1042 | 0 | |
| 1043 | 0 | public ArrayList<CasosTeste> getCasosDeTeste() { |
| 1044 | 0 | return casosDeTeste; |
| 1045 | 0 | } |
| 1046 | 0 | |
| 1047 | 0 | public void setCasosDeTeste(ArrayList<CasosTeste> casosDeTeste) { |
| 1048 | 0 | this.casosDeTeste = casosDeTeste; |
| 1049 | 0 | } |
| 1050 | 0 | |
| 1051 | 0 | public ArrayList<CasosTeste> getCasosDeTesteData() { |
| 1052 | 0 | return casosDeTesteData; |
| 1053 | 0 | } |
| 1054 | 0 | |
| 1055 | 0 | public void setCasosDeTesteData(ArrayList<CasosTeste> casosDeTesteData) { |
| 1056 | 0 | this.casosDeTesteData = casosDeTesteData; |
| 1057 | 0 | } |
| 1058 | 0 | |
| 1059 | 0 | public boolean pontoVerificacao(String s) { |
| 1060 | 0 | if (s.contains("Verificar")) { |
| 1061 | 0 | return true; |
| 1062 | 0 | } |
| 1063 | 0 | if (s.contains("Validar")) { |
| 1064 | 0 | return true; |
| 1065 | 0 | } |
| 1066 | 0 | return false; |
| 1067 | 0 | } |
| 1068 | 0 | |
| 1069 | 0 | public String tiraCaracteres(String s) { |
| 1070 | 0 | return s.replace("�", "c").replace("�", "e").replace("�", "a").replace( |
| 1071 | 0 | "\"", "").replace("�", "o").replace("�", "o").replace("�", "u") |
| 1072 | 0 | .replace("�", "i").replace("�", "a").replace("�", "a").replace( |
| 1073 | 0 | "�", "U").replace("�", "").replace("�", "").replace( |
| 1074 | 0 | "�", "").replace("�", "").replace("�", "a").replace( |
| 1075 | 0 | "�", "o").replace("�", "e").replace("�", "o").replace( |
| 1076 | 0 | "�", "A").replace("�", "A").replace("�", "C").replace( |
| 1077 | 0 | "�", "O").replace("�", "I").replace("�", "o").replace( |
| 1078 | 0 | "�", "O").replace("�", " "); |
| 1079 | 0 | } |
| 1080 | 0 | |
| 1081 | 0 | public void bestPathProbalilidadeRandom(Fluxo flow, int number, |
| 1082 | 0 | CasosTeste casoTeste, int points, CasoUso useCase) { |
| 1083 | 0 | |
| 1084 | 0 | try { |
| 1085 | 0 | if (!(Algoritmo.flows.containsKey(flow.getName()))) { |
| 1086 | 0 | Algoritmo.flows.put(flow.getName(), flow); |
| 1087 | 0 | } |
| 1088 | 0 | |
| 1089 | 0 | casoTeste.getFlows().add(flow); |
| 1090 | 0 | |
| 1091 | 0 | while (number <= flow.getSteps().size() - 1) { |
| 1092 | 0 | |
| 1093 | 0 | Step step = (Step) ((Fluxo) Algoritmo.flows.get(flow.getName())) |
| 1094 | 0 | .getSteps().get(number); |
| 1095 | 0 | |
| 1096 | 0 | CasoTesteStep casoStep = new CasoTesteStep(); |
| 1097 | 0 | |
| 1098 | 0 | casoStep.setStep(step); |
| 1099 | 0 | |
| 1100 | 0 | casoTeste.getPassos().add(casoStep); |
| 1101 | 0 | step.setCoberto(true); |
| 1102 | 0 | int numeroExecucoes = step.getNumberOfExecution(); |
| 1103 | 0 | if (numeroExecucoes > (useCase.getFlows().size() * 2)) { |
| 1104 | 0 | break; |
| 1105 | 0 | } |
| 1106 | 0 | step.setNumberOfExecution(numeroExecucoes + 1); |
| 1107 | 0 | |
| 1108 | 0 | if (step.getRegras().size() > 0) { |
| 1109 | 0 | for (int i = 0; i <= step.getRegras().size() - 1; i++) { |
| 1110 | 0 | RegraNegocio regra = ((RegraNegocio) step.getRegras() |
| 1111 | 0 | .get(i)); |
| 1112 | 0 | |
| 1113 | 0 | if ((!(this.regrasCobertas.containsKey(regra.getName()))) |
| 1114 | 0 | || (regra.isReuse())) { |
| 1115 | 0 | |
| 1116 | 0 | for (Object elemento : regra.getSteps()) { |
| 1117 | 0 | |
| 1118 | 0 | Step stepRegra = (Step) elemento; |
| 1119 | 0 | |
| 1120 | 0 | CasoTesteStep casoStepAux = new CasoTesteStep(); |
| 1121 | 0 | |
| 1122 | 0 | casoStepAux.setStep(stepRegra); |
| 1123 | 0 | |
| 1124 | 0 | casoTeste.getPassos().add(casoStepAux); |
| 1125 | 0 | } |
| 1126 | 0 | this.regrasCobertas.put(regra.getName(), regra); |
| 1127 | 0 | } |
| 1128 | 0 | |
| 1129 | 0 | } |
| 1130 | 0 | |
| 1131 | |
} |
| 1132 | 0 | |
| 1133 | 0 | if (step.getLinks().size() > 0) { |
| 1134 | 0 | for (int i = 0; i <= step.getLinks().size() - 1; i++) { |
| 1135 | 0 | |
| 1136 | 0 | Link link1 = ((Link) step.getLinks().get(i)); |
| 1137 | 0 | double probabilidade = link1.getProbabilidade(); |
| 1138 | 0 | double random = Math.random(); |
| 1139 | 0 | if (probabilidade >= random) { |
| 1140 | 0 | if (link1.getFlow() != null) { |
| 1141 | 0 | if (!(Algoritmo.flows.containsKey(link1 |
| 1142 | 0 | .getFlow().getName()))) { |
| 1143 | 0 | Algoritmo.flows.put(link1.getFlow() |
| 1144 | 0 | .getName(), link1.getFlow()); |
| 1145 | 0 | } |
| 1146 | 0 | if (((Fluxo) (Algoritmo.flows.get(link1 |
| 1147 | 0 | .getFlow().getName()))).steps.size() == 0) { |
| 1148 | 0 | Algoritmo.flows.put(link1.getFlow() |
| 1149 | 0 | .getName(), link1.getFlow()); |
| 1150 | 0 | } |
| 1151 | 0 | |
| 1152 | 0 | if (Fluxo |
| 1153 | 0 | .getStepNumber(((Fluxo) Algoritmo.flows |
| 1154 | 0 | .get(link1.getFlow().getName()))) != Fluxo |
| 1155 | 0 | .getStepNumberCover(((Fluxo) Algoritmo.flows |
| 1156 | 0 | .get(link1.getFlow().getName())))) { |
| 1157 | 0 | |
| 1158 | 0 | CasosTeste casoTeste1 = new CasosTeste(); |
| 1159 | 0 | casoTeste1.getFlows().addAll( |
| 1160 | 0 | casoTeste.getFlows()); |
| 1161 | 0 | casoTeste1.getPassos().addAll(0, |
| 1162 | 0 | casoTeste.getPassos()); |
| 1163 | 0 | |
| 1164 | 0 | RuleDelete ruleDelete = new RuleDelete(); |
| 1165 | 0 | ruleDelete.ruleDelete(casoTeste1, this |
| 1166 | 0 | .getRegrasCobertas()); |
| 1167 | |
|
| 1168 | 0 | retornaCenarios(((Fluxo) Algoritmo.flows |
| 1169 | 0 | .get(link1.getFlow().getName())), |
| 1170 | 0 | link1.getStepNumber(), casoTeste1, |
| 1171 | 0 | points, useCase); |
| 1172 | 0 | |
| 1173 | 0 | } |
| 1174 | |
} |
| 1175 | 0 | } |
| 1176 | 0 | |
| 1177 | 0 | } |
| 1178 | 0 | } |
| 1179 | 0 | number++; |
| 1180 | 0 | } |
| 1181 | 0 | |
| 1182 | 0 | casoTeste.setNumeroMaximoCasosTeste(flow.getNumeroMaximo()); |
| 1183 | 0 | casosDeTeste.add(casoTeste); |
| 1184 | 0 | } catch (StackOverflowError e) { |
| 1185 | 0 | casoTeste.setNumeroMaximoCasosTeste(flow.getNumeroMaximo()); |
| 1186 | 0 | casosDeTeste.add(casoTeste); |
| 1187 | 0 | } |
| 1188 | 0 | |
| 1189 | 0 | } |
| 1190 | 0 | |
| 1191 | |
public void bestPathProbalilidade(Fluxo flow, int number, |
| 1192 | 0 | CasosTeste casoTeste, int points, CasoUso useCase, |
| 1193 | 0 | double probabilidadeMinima) { |
| 1194 | |
|
| 1195 | 0 | try { |
| 1196 | 0 | if (!(Algoritmo.flows.containsKey(flow.getName()))) { |
| 1197 | 0 | Algoritmo.flows.put(flow.getName(), flow); |
| 1198 | |
} |
| 1199 | 0 | |
| 1200 | 0 | casoTeste.getFlows().add(flow); |
| 1201 | 0 | |
| 1202 | 0 | while (number <= flow.getSteps().size() - 1) { |
| 1203 | 0 | |
| 1204 | 0 | Step step = (Step) ((Fluxo) Algoritmo.flows.get(flow.getName())) |
| 1205 | 0 | .getSteps().get(number); |
| 1206 | |
|
| 1207 | 0 | CasoTesteStep casoStep = new CasoTesteStep(); |
| 1208 | |
|
| 1209 | 0 | casoStep.setStep(step); |
| 1210 | |
|
| 1211 | 0 | casoTeste.getPassos().add(casoStep); |
| 1212 | 0 | step.setCoberto(true); |
| 1213 | 0 | int numeroExecucoes = step.getNumberOfExecution(); |
| 1214 | 0 | if (numeroExecucoes > (useCase.getFlows().size() * 2)) { |
| 1215 | 0 | break; |
| 1216 | 0 | } |
| 1217 | 0 | step.setNumberOfExecution(numeroExecucoes + 1); |
| 1218 | 0 | |
| 1219 | 0 | if (step.getRegras().size() > 0) { |
| 1220 | 0 | for (int i = 0; i <= step.getRegras().size() - 1; i++) { |
| 1221 | 0 | RegraNegocio regra = ((RegraNegocio) step.getRegras() |
| 1222 | 0 | .get(i)); |
| 1223 | 0 | |
| 1224 | 0 | if ((!(this.regrasCobertas.containsKey(regra.getName()))) |
| 1225 | 0 | || (regra.isReuse())) { |
| 1226 | 0 | |
| 1227 | 0 | for (Object elemento : regra.getSteps()) { |
| 1228 | 0 | |
| 1229 | 0 | Step stepRegra = (Step) elemento; |
| 1230 | |
|
| 1231 | 0 | CasoTesteStep casoStepAux = new CasoTesteStep(); |
| 1232 | 0 | |
| 1233 | 0 | casoStepAux.setStep(stepRegra); |
| 1234 | 0 | |
| 1235 | 0 | casoTeste.getPassos().add(casoStepAux); |
| 1236 | |
} |
| 1237 | 0 | this.regrasCobertas.put(regra.getName(), regra); |
| 1238 | 0 | } |
| 1239 | 0 | |
| 1240 | 0 | } |
| 1241 | 0 | |
| 1242 | |
} |
| 1243 | 0 | |
| 1244 | 0 | if (step.getLinks().size() > 0) { |
| 1245 | 0 | for (int i = 0; i <= step.getLinks().size() - 1; i++) { |
| 1246 | |
|
| 1247 | 0 | Link link1 = ((Link) step.getLinks().get(i)); |
| 1248 | 0 | double probabilidade = link1.getProbabilidade(); |
| 1249 | 0 | |
| 1250 | 0 | if (probabilidade >= probabilidadeMinima) { |
| 1251 | 0 | if (link1.getFlow() != null) { |
| 1252 | 0 | if (!(Algoritmo.flows.containsKey(link1 |
| 1253 | 0 | .getFlow().getName()))) { |
| 1254 | 0 | Algoritmo.flows.put(link1.getFlow() |
| 1255 | 0 | .getName(), link1.getFlow()); |
| 1256 | |
} |
| 1257 | 0 | if (((Fluxo) (Algoritmo.flows.get(link1 |
| 1258 | 0 | .getFlow().getName()))).steps.size() == 0) { |
| 1259 | 0 | Algoritmo.flows.put(link1.getFlow() |
| 1260 | 0 | .getName(), link1.getFlow()); |
| 1261 | 0 | } |
| 1262 | 0 | |
| 1263 | 0 | if (Fluxo |
| 1264 | 0 | .getStepNumber(((Fluxo) Algoritmo.flows |
| 1265 | 0 | .get(link1.getFlow().getName()))) != Fluxo |
| 1266 | 0 | .getStepNumberCover(((Fluxo) Algoritmo.flows |
| 1267 | 0 | .get(link1.getFlow().getName())))) { |
| 1268 | 0 | |
| 1269 | 0 | CasosTeste casoTeste1 = new CasosTeste(); |
| 1270 | 0 | casoTeste1.getFlows().addAll( |
| 1271 | 0 | casoTeste.getFlows()); |
| 1272 | 0 | casoTeste1.getPassos().addAll(0, |
| 1273 | 0 | casoTeste.getPassos()); |
| 1274 | |
|
| 1275 | 0 | RuleDelete ruleDelete = new RuleDelete(); |
| 1276 | 0 | ruleDelete.ruleDelete(casoTeste1, this |
| 1277 | 0 | .getRegrasCobertas()); |
| 1278 | |
|
| 1279 | 0 | retornaCenarios(((Fluxo) Algoritmo.flows |
| 1280 | 0 | .get(link1.getFlow().getName())), |
| 1281 | 0 | link1.getStepNumber(), casoTeste1, |
| 1282 | 0 | points, useCase); |
| 1283 | |
|
| 1284 | |
} |
| 1285 | |
} |
| 1286 | |
} |
| 1287 | |
|
| 1288 | |
} |
| 1289 | |
} |
| 1290 | 0 | number++; |
| 1291 | |
} |
| 1292 | |
|
| 1293 | 0 | casoTeste.setNumeroMaximoCasosTeste(flow.getNumeroMaximo()); |
| 1294 | 0 | casosDeTeste.add(casoTeste); |
| 1295 | 0 | } catch (StackOverflowError e) { |
| 1296 | 0 | casoTeste.setNumeroMaximoCasosTeste(flow.getNumeroMaximo()); |
| 1297 | 0 | casosDeTeste.add(casoTeste); |
| 1298 | |
} |
| 1299 | |
|
| 1300 | 0 | } |
| 1301 | |
} |