Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add maven/jib and java/jib generators #25731

Merged
merged 3 commits into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
153 changes: 0 additions & 153 deletions generators/cucumber/__snapshots__/generator.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -200,156 +200,3 @@ testng = { module = "org.testng:testng", version = "'TESTNG-VERSION'" }
},
}
`;

exports[`generator - cucumber with unknown buildTool should match files snapshot 1`] = `
{
".yo-rc.json": {
"contents": "{
"generator-jhipster": {
"baseName": "jhipster",
"buildTool": "unknown",
"creationTimestamp": 1577836800000,
"entities": [],
"jhipsterVersion": "8.2.1",
"testFrameworks": ["cucumber"]
}
}
",
"stateCleared": "modified",
},
"src/test/java/com/mycompany/myapp/cucumber/CucumberIT.java": {
"contents": "package com.mycompany.myapp.cucumber;

import com.mycompany.myapp.IntegrationTest;
import io.cucumber.junit.platform.engine.Cucumber;

@Cucumber
@IntegrationTest
class CucumberIT {}
",
"stateCleared": "modified",
},
"src/test/java/com/mycompany/myapp/cucumber/CucumberTestContextConfiguration.java": {
"contents": "package com.mycompany.myapp.cucumber;

import com.mycompany.myapp.IntegrationTest;
import io.cucumber.spring.CucumberContextConfiguration;
import org.springframework.test.context.web.WebAppConfiguration;

@CucumberContextConfiguration
@IntegrationTest
@WebAppConfiguration
public class CucumberTestContextConfiguration {}
",
"stateCleared": "modified",
},
"src/test/java/com/mycompany/myapp/cucumber/stepdefs/StepDefs.java": {
"contents": "package com.mycompany.myapp.cucumber.stepdefs;

import org.springframework.test.web.servlet.ResultActions;

public abstract class StepDefs {

protected ResultActions actions;
}
",
"stateCleared": "modified",
},
"src/test/java/com/mycompany/myapp/cucumber/stepdefs/UserStepDefs.java": {
"contents": "package com.mycompany.myapp.cucumber.stepdefs;

import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;

import com.mycompany.myapp.security.AuthoritiesConstants;
import com.mycompany.myapp.web.rest.UserResource;
import io.cucumber.java.Before;
import io.cucumber.java.en.Then;
import io.cucumber.java.en.When;
import java.util.ArrayList;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.context.SecurityContext;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.User;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;

public class UserStepDefs extends StepDefs {

@Autowired
private UserResource userResource;

private MockMvc userResourceMock;

@Before
public void setup() {
List<GrantedAuthority> grantedAuthorities = new ArrayList<>();
grantedAuthorities.add(
new SimpleGrantedAuthority(AuthoritiesConstants.ADMIN)
);
User principal = new User(
"admin",
"",
true,
true,
true,
true,
grantedAuthorities
);
Authentication authentication = new UsernamePasswordAuthenticationToken(
principal,
principal.getPassword(),
principal.getAuthorities()
);
SecurityContext context = SecurityContextHolder.createEmptyContext();
context.setAuthentication(authentication);
SecurityContextHolder.setContext(context);
this.userResourceMock = MockMvcBuilders.standaloneSetup(
userResource
).build();
}

@When("I search user {string}")
public void i_search_user(String userId) throws Throwable {
actions = userResourceMock.perform(
get("/api/admin/users/" + userId).accept(MediaType.APPLICATION_JSON)
);
}

@Then("the user is found")
public void the_user_is_found() throws Throwable {
actions
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE));
}

@Then("his last name is {string}")
public void his_last_name_is(String lastName) throws Throwable {
actions.andExpect(jsonPath("$.lastName").value(lastName));
}
}
",
"stateCleared": "modified",
},
"src/test/resources/com/mycompany/myapp/cucumber/gitkeep": {
"contents": "",
"stateCleared": "modified",
},
"src/test/resources/com/mycompany/myapp/cucumber/user.feature": {
"contents": "Feature: User management

Scenario: Retrieve administrator user
When I search user 'admin'
Then the user is found
And his last name is 'Administrator'
",
"stateCleared": "modified",
},
}
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`generator - java:build-tool with defaults options should match files snapshot 1`] = `{}`;
86 changes: 86 additions & 0 deletions generators/java/generators/build-tool/generator.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/**
* Copyright 2013-2024 the original author or authors from the JHipster project.
*
* This file is part of the JHipster project, see https://www.jhipster.tech/
* for more information.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { basename, dirname, resolve } from 'node:path';
import { fileURLToPath } from 'node:url';
import { before, it, describe, expect } from 'esmocha';

import { shouldSupportFeatures, testBlueprintSupport } from '../../../../test/support/tests.js';
import { defaultHelpers as helpers, result } from '../../../../testing/index.js';
import Generator from './index.js';

const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);

const generator = `${basename(resolve(__dirname, '../../'))}:${basename(__dirname)}`;

describe(`generator - ${generator}`, () => {
shouldSupportFeatures(Generator);
describe('blueprint support', () => testBlueprintSupport(generator));

describe('with defaults options', () => {
before(async () => {
await helpers.runJHipster(generator).withJHipsterConfig().withMockedSource();
});

it('should match files snapshot', () => {
expect(result.sourceCallsArg).toMatchSnapshot();
});
});

describe('buildTool option', () => {
describe('maven', () => {
let runResult;
before(async () => {
runResult = await helpers
.runJHipster(generator)
.withJHipsterConfig({
buildTool: 'maven',
})
.withSkipWritingPriorities()
.withMockedGenerators(['jhipster:maven', 'jhipster:gradle']);
});

it('should compose with maven generator', () => {
expect(runResult.mockedGenerators['jhipster:maven'].calledOnce).toBe(true);
});
it('should not compose with others buildTool generators', () => {
expect(runResult.mockedGenerators['jhipster:gradle'].notCalled).toBe(true);
});
});
describe('gradle', () => {
let runResult;
before(async () => {
runResult = await helpers
.runJHipster(generator)
.withJHipsterConfig({
buildTool: 'gradle',
})
.withSkipWritingPriorities()
.withMockedGenerators(['jhipster:maven', 'jhipster:gradle']);
});

it('should compose with gradle generator', () => {
expect(runResult.mockedGenerators['jhipster:gradle'].called).toBe(true);
});
it('should not compose with others buildTool generators', () => {
expect(runResult.mockedGenerators['jhipster:maven'].notCalled).toBe(true);
});
});
});
});
Loading
Loading