0

I am running IntelliJ Idea 2017 on windows 10, I'm working on a springboot project, when I try to run simple test case I get following error.

Caused by: org.xml.sax.SAXParseException; systemId: file:..../src/test/java/com/hero/project/controller/MainControllerTest.java; lineNumber: 1; columnNumber: 1; Content is not allowed in prolog.
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:203)
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.fatalError(ErrorHandlerWrapper.java:177)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:441)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:368)
at com.sun.org.apache.xerces.internal.impl.XMLScanner.reportFatalError(XMLScanner.java:1436)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(XMLDocumentScannerImpl.java:999)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:606)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:117)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:510)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:848)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:777)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1213)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:649)
at org.apache.tools.ant.helper.ProjectHelper2.parse(ProjectHelper2.java:281)
... 6 more

Here is test case it's complaining about

package com.hero.project.controller;
import org.junit.Before;
import org.junit.Test;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.view;

public class MainControllerTest {
    private MockMvc mockMvc;
    private MainController homeController;
    @Before
    public void setUp() throws Exception {
        homeController = new MainController();
        mockMvc = MockMvcBuilders.standaloneSetup(homeController).build();
    }

    @Test
    public void index() throws Exception {
        mockMvc.perform(get("/"))
                .andExpect(status().isOk())
                .andExpect(view().name("index"));
    }

}

This is MainController class.

package com.hero.project.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.Calendar;

@Controller
public class MainController {

    @RequestMapping("/")
    public String index(Model model){
        int year = Calendar.getInstance().get(Calendar.YEAR);
        model.addAttribute("year",year);
        return "index";
    }

}

Note: Same code using same version of Intellij Idea 2017 on Mac works fine. I am having hard time debugging this issue. I will appreciate any help. Thank you

Ronnie Kumar
  • 635
  • 5
  • 18
  • Possible duplicate of http://stackoverflow.com/questions/32772352/java-file-content-not-allowed-in-prolog – duffymo Apr 21 '17 at 14:20
  • No it's not I tried same solution but did not work and seems like it's problem with Intellij 2017. And I created this project using Intellij Idea from scratch – Ronnie Kumar Apr 21 '17 at 14:25
  • I'm using IntelliJ 2017 and experiencing no such problems. I think it's your code. – duffymo Apr 21 '17 at 14:47
  • What about this one? http://stackoverflow.com/questions/25652140/intellij-content-is-not-allowed-in-prolog – duffymo Apr 21 '17 at 14:51
  • Two SO questions about your problem. I'd suggest that you do a search here and see who else had your problem. – duffymo Apr 21 '17 at 14:52
  • of course I did search before posting question here and try deleting .idea folder still having same issue – Ronnie Kumar Apr 21 '17 at 14:59
  • Possible duplicate of [Java file: Content not allowed in prolog](http://stackoverflow.com/questions/32772352/java-file-content-not-allowed-in-prolog) – RasmusW Apr 21 '17 at 18:51

1 Answers1

0

Finally, I figured it out. It was this plugin "Ant Debugger" causing the issue. I disabled it and run test and boom it works.

Ronnie Kumar
  • 635
  • 5
  • 18