@@ -0,0 +1,2290 @@
+/* LanguageTool, a natural language style checker %0A * Copyright (C) 2020 Daniel Naber (http://www.danielnaber.de)%0A * %0A * This library is free software; you can redistribute it and/or%0A * modify it under the terms of the GNU Lesser General Public%0A * License as published by the Free Software Foundation; either%0A * version 2.1 of the License, or (at your option) any later version.%0A *%0A * This library is distributed in the hope that it will be useful,%0A * but WITHOUT ANY WARRANTY; without even the implied warranty of%0A * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU%0A * Lesser General Public License for more details.%0A *%0A * You should have received a copy of the GNU Lesser General Public%0A * License along with this library; if not, write to the Free Software%0A * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301%0A * USA%0A */%0Apackage org.languagetool.server;%0A%0Aimport com.fasterxml.jackson.databind.ObjectMapper;%0Aimport org.junit.Ignore;%0Aimport org.junit.Test;%0Aimport org.languagetool.tools.Tools;%0A%0Aimport java.io.IOException;%0Aimport java.net.URLEncoder;%0Aimport java.util.List;%0Aimport java.util.Map;%0A%0Apublic class BertResortingBugTest %7B%0A%0A  @Test%0A  @Ignore(%22shows bugs - for interactive use%22)%0A  public void testHttpApi() throws IOException %7B%0A    String s = %22A teext.%5CnAn err%C3%B6r-free text.%5CnSo much teext.%22;  // must exactly match 'data'%0A    String data = %22%7B%5C%22annotation%5C%22:%5B%7B%5C%22text%5C%22:%5C%22A teext.%5C%22%7D,%7B%5C%22markup%5C%22:%5C%22%5C%5Cn%5C%22,%5C%22interpretAs%5C%22:%5C%22%5C%5Cn%5C%5Cn%5C%22%7D,%7B%5C%22text%5C%22:%5C%22An err%C3%B6r-free text.%5C%22%7D,%7B%5C%22markup%5C%22:%5C%22%5C%5Cn%5C%22,%5C%22interpretAs%5C%22:%5C%22%5C%5Cn%5C%5Cn%5C%22%7D,%7B%5C%22text%5C%22:%5C%22So much teext.%5C%22%7D%5D%7D%22;%0A    String server = %22http://localhost:8081%22;%0A    String url = server + %22/v2/check?data=%22 + URLEncoder.encode(data, %22utf-8%22) + %22&language=en-US%22;%0A    String json = HTTPTools.checkAtUrl(Tools.getUrl(url));%0A    ObjectMapper mapper = new ObjectMapper();%0A    Map map = mapper.readValue(json, Map.class);%0A    List matches = (List) map.get(%22matches%22);%0A    for (Object match : matches) %7B%0A      Map m = (Map) match;%0A      int offset = Integer.parseInt(m.get(%22offset%22).toString());%0A      int length = Integer.parseInt(m.get(%22length%22).toString());%0A      // crashes with %22String index out of range%22 if server uses BERT re-sorting:%0A      System.out.println(s.substring(offset, offset + length));%0A    %7D%0A  %7D%0A%0A%7D%0A

test to reproduce bug #2969