Skip to content

Commit 5d3f555

Browse files
Added test for generation
1 parent e8809e2 commit 5d3f555

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0"?>
2+
<routes xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Webapi:etc/webapi.xsd">
4+
<route url="/V1/test/foo/save" method="POST">
5+
<service class="Foo\Bar\Api\SaveFoo" method="execute"/>
6+
<resources>
7+
<resource ref="self"/>
8+
</resources>
9+
</route>
10+
</routes>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
6+
package com.magento.idea.magento2plugin.actions.generation.generator;
7+
8+
import com.intellij.psi.PsiFile;
9+
import com.magento.idea.magento2plugin.actions.generation.data.xml.WebApiXmlRouteData;
10+
import com.magento.idea.magento2plugin.actions.generation.generator.xml.WebApiDeclarationGenerator;
11+
import com.magento.idea.magento2plugin.magento.files.ModuleWebApiXmlFile;
12+
13+
public class WebApiXmlDeclarationGeneratorTest extends BaseGeneratorTestCase {
14+
15+
private static final String EXPECTED_DIRECTORY = "src/app/code/Foo/Bar/etc";
16+
private static final String COULD_NOT_GENERATE_MESSAGE =
17+
ModuleWebApiXmlFile.DECLARATION_TEMPLATE + " could not be generated!";
18+
private static final String MODULE_NAME = "Foo_Bar";
19+
private static final String URL = "test/foo/save";
20+
private static final String HTTP_METHOD = "POST";
21+
private static final String SERVICE_CLASS = "Foo\\Bar\\Api\\SaveFoo";
22+
private static final String SERVICE_METHOD = "execute";
23+
private static final String RESOURCE = "self";
24+
25+
/**
26+
* Test generation of web api xml declaration for a service.
27+
*/
28+
public void testGenerateWebApiXmlDeclarationForService() {
29+
final WebApiXmlRouteData data = new WebApiXmlRouteData(
30+
MODULE_NAME,
31+
URL,
32+
HTTP_METHOD,
33+
SERVICE_CLASS,
34+
SERVICE_METHOD,
35+
RESOURCE
36+
);
37+
final WebApiDeclarationGenerator generator = new WebApiDeclarationGenerator(
38+
data,
39+
myFixture.getProject()
40+
);
41+
final PsiFile result = generator.generate("test");
42+
43+
if (result == null) {
44+
fail(COULD_NOT_GENERATE_MESSAGE);
45+
}
46+
47+
assertGeneratedFileIsCorrect(
48+
myFixture.configureByFile(this.getFixturePath(ModuleWebApiXmlFile.FILE_NAME)),
49+
EXPECTED_DIRECTORY,
50+
result
51+
);
52+
}
53+
}

0 commit comments

Comments
 (0)