SuperX-Kernmodul
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

95 lines
3.3 KiB

package de.superx.rest;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.io.IOException;
import java.sql.SQLException;
import java.text.ParseException;
import java.util.List;
import java.util.Map;
import javax.xml.transform.TransformerException;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.security.core.userdetails.UserDetails;
import de.memtext.tree.KeyParentEqualException;
import de.memtext.tree.NoMainEntryException;
import de.superx.BaseDbTest;
import de.superx.common.DBServletException;
import de.superx.common.InvalidDataTypeException;
import de.superx.common.SichtException;
import de.superx.common.UngueltigeEingabeException;
import de.superx.rest.model.TreeNode;
import de.superx.rest.model.View;
import de.superx.rest.model.ViewGroup;
import de.superx.spring.TestUserServiceImpl;
import freemarker.template.TemplateException;
public class ReportTest extends BaseDbTest {
private static final int TID = 18540;
@Autowired
Report report;
MockHttpServletRequest req;
@Before
public void init() {
Map<String,String> params = Map.ofEntries(
Map.entry("Jahr", "2025"),
Map.entry("Hochschule", "9991"),
Map.entry("Monat", "1"),
Map.entry("Ausgabe des Berichts", "STLI*tabelle_html.xsl*text/html")
);
req = new MockHttpServletRequest();
req.setParameters(params);
getTestUserService().createTestUser(true, List.of(Integer.valueOf(TID)));
}
@After
public void deinit() {
getTestUserService().setUserDetails(null);
}
@Test
public void testReportApiAvailable() {
assertNotNull("Report rest api available", report);
}
@Test
public void testUserAvailable() {
UserDetails ud = getTestUserService().currentUserDetails();
assertNotNull("UserDetails available", ud);
}
@Test
public void testGetViews() throws ParseException, KeyParentEqualException, NoMainEntryException, SQLException, InvalidDataTypeException, SichtException, UngueltigeEingabeException, TemplateException, CloneNotSupportedException, IOException, DBServletException, TransformerException {
ViewGroup vg = report.getViews(TID, "Hochschule", req);
assertNotNull("Views available", vg);
}
@Test
public void testGetView() throws ParseException, KeyParentEqualException, NoMainEntryException, SQLException, InvalidDataTypeException, SichtException, UngueltigeEingabeException, TemplateException, CloneNotSupportedException, IOException, DBServletException, TransformerException {
ViewGroup vg = report.getViews(TID, "Hochschule", req);
int viewId = -1;
for (View v : vg.views) {
if (v.name.equals("Hochschulen")) {
viewId = v.id;
break;
}
}
assertTrue("View found in ViewGroup", viewId != -1);
List<TreeNode> view = report.getView(TID, "Hochschule", viewId, "today", req);
assertNotNull("View available", view);
assertTrue("Exactly one view found", view.size() == 1);
}
}