|
| 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